MFC Visual Studio 2008中的.SetLength [英] .SetLength in MFC Visual Studio 2008

查看:111
本文介绍了MFC Visual Studio 2008中的.SetLength的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在类中声明了CString变量为public,但是当我尝试设置最大长度"m_string1.SetLength(9)"时,出现编译错误无法访问在类''ATL :: CSimpleStringT <中声明的私有成员; BaseType,t_bMFCDLL> :: SetLength''.

这在编辑控制箱中使用.

这里的初学者对ATL的运行情况一无所知?

任何帮助表示赞赏...

谢谢,

斯科特

我想将用户限制为输入8个字符的编辑控制框...
我以为创建编辑框的选项中会有一个MAXLENTH,但那里什么也没有.
猜猜我需要从CString更改为char [9]吗?

我如何找到CString(其基类")或任何其他基类?我不知道,这些是我缺少的简单内容.

I have CString variables declared as public in my class, yet when I try to set a maximum length "m_string1.SetLength(9)" I get a compile error "cannot access private member declared in class ''ATL::CSimpleStringT<BaseType,t_bMFCDLL>::SetLength''.

This is being used in an edit control box.

Beginner here with no concept of what''s going on with ATL???

Any help appreciated...

Thanks,

Scott

I want to limit the user to 8 characters of input to an edit control box...
I thought there would be a MAXLENTH in the options where I created the edit boxes, but nothing there.
Guess I need to change from CString to char[9]?

How do I find CString''s ("its base class") or any other base class? I have no idea, these are the simple things I''m missing.

推荐答案

斯科特,你好,
CString没有最大长度的概念,长度取决于内容.
如果希望设置分配的大小以避免复制,请使用void CString::Preallocate(int length).
欢呼声,
AR

问题更新后进行

如果要限制编辑控件接受的文本的长度,请向其发送EM_SETLIMITTEXT消息:
Hi Scott,
There is no concept of a maximum length for CString, the length depends on the content.
If you wish to set the allocated size to avoid copying use void CString::Preallocate(int length).
cheers,
AR

Edit after question update:

If you want to limit the length of accepted text for an Edit Control send it the EM_SETLIMITTEXT message:
::SendMessage(hWndofMyControl, EM_SETLIMITTEXT, 8, 0); // limit to 8 characters accepted


不知道为什么要自己直接设置CString的长度... ???

CString是动态的,这意味着它们将根据您希望它们保存的数据自行分配任何内存.通过设置字符串的长度,您到底要做什么?

[edit]
顺便说一句,SetLength不是CString的成员,它不是其基类的成员,这就是为什么会出现错误的原因.这意味着在常规条件下,您不需要访问该成员.您要Truncate()吗?
[/edit]
Not sure why you''re trying to set the length of a CString yourself directly... ???

CStrings are dynamic, meaning they''ll allocate any memory themselves based on what data you want them to hold. What are you really trying to do by setting the length of that string?

[edit]
By the way, SetLength is not a member of CString, its a member of its base class, which is why you get the error. Meaning under regular conditions, you shouldn''t need to access that member. Are you trying to Truncate()?
[/edit]


这篇关于MFC Visual Studio 2008中的.SetLength的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆