私はTEditから派生した新しいコンポーネントを作成しました。以下のコードでは、AllowValuesをtrueに設定した後、MaxLengthプロパティを10に設定しています。CustomComponent(TEDIT)を設定するMaxLengthプロパティが機能しません
フォームにコンポーネントを設定し、AllowValuesをtrueに設定してとし、アプリケーションと編集ボックスを実行して10文字以上を許可しています。私のコードで何が間違っていますか?
unit DummyEdit;
interface
uses
SysUtils, Classes, Controls, StdCtrls,Dialogs,Windows,Messages;
type
TDUMMYEdit = class(TEdit)
private
{ Private declarations }
FAllowValues : Boolean;
FMaxLength: Integer;
Procedure SetAllowValues(Value : Boolean);
procedure SetMaxLength(Value: Integer);
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
Property AllowValues : Boolean read FAllowValues write SetAllowValues;
property MaxLength: Integer read FMaxLength write SetMaxLength default 0;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DUMMY', [TDUMMYEdit]);
end;
{ TDUMMYEdit }
procedure TDUMMYEdit.SetAllowValues(Value: Boolean);
begin
if FAllowValues <> value then
FAllowValues := Value;
if FAllowValues then
MaxLength := 10
else
MaxLength := 0;
end;
procedure TDUMMYEdit.SetMaxLength(Value: Integer);
begin
if FMaxLength <> Value then
begin
FMaxLength := Value;
if HandleAllocated then SendMessage(Handle, EM_LIMITTEXT, Value, 0);
end;
end;
end.
私はコンポーネント作成に非常に新しく、私は遊んでいます。私はCreatewndをチェックします。 – DelphiLearner
MaxLengthプロパティが削除されていればそれが機能しています。 – DelphiLearner
うれしいです。元のコードと 'CreateWnd'を使って解決策を追加しました。 – nil