主要代码如下:
。。。
type
TTabBaseFieldsProperty=class(TStringProperty)
public
function GetAttributes:TPropertyAttributes;override;
procedure Edit;override;
end;//属性编辑器用
TRelatedTab = class(TPanel) //控件,继承自 panel
private
FDbgBase:TDBGrid;
。。。
FTabBaseFields:string;
procedure SetTabBaseFields(value:string);
protected
procedure CreateTab(Qry:TQuery;sqlstr:string);
procedure Create_B_Edits;
public
constructor create(AOwner:TComponent);override;
destructor destroy;override;
published
property TabBaseFields:string read FTabBaseFields write SetTabBaseFields;
end;
procedure Register;
implementation
uses
FieldsFrm;
procedure Register;
begin
RegisterComponents('RelatedTab', [TRelatedTab]);
RegisterPropertyEditor(TypeInfo(string),TRelatedTab,'TabBaseFields',TTabBaseFieldsProperty);
end;
procedure TRelatedTab.SetTabBaseFields(value:string);
begin
try
FTabBaseFields:=Value;
except
on Exception do
FTabBaseFields:=Value;
end;
end;
procedure TRelatedTab.Create_B_Edits; //动态生成 bF_count 个 LabelEdit
var jj:integer;
NewEdit:TLabeledEdit;
begin
for jj:=1 to bF_count do
begin
NewEdit:=TLabeledEdit.Create(self);///*************这里是否错了?
with NewEdit do
begin
Parent:=self;
Width:=75;
Height:=21;
Left:=jj*75;
Top:=screen.ActiveControl.Height*3 div 5 +6;
Name:='ed_B'+inttostr(jj);
end;
end;
end;
function TTabBaseFieldsProperty.GetAttributes: TPropertyAttributes;
begin
result:=[paDialog,paMultiselect];
end;
procedure TTabBaseFieldsProperty.Edit;//就是想在这里生成 LabelEdit*****
begin
FrmFields:=TFrmFields.Create(nil);
try
FrmFields.FieldsList:=TStringList(GetOrdValue);
if FrmFields.ShowModal=mrOK then
SetOrdValue(longint(FrmFields.FieldsList.Text));
//在这里完成功能:生成几个 LabelEdit
finally
FrmFields.FieldsList.Free;
FrmFields.Free;
end;
end;
//*************另外引用了另一个 。dfm 文件,如上面 implementation 后,附上
type
TFrmFields = class(TForm)
btConfirm: TRzBitBtn;
btCancel: TRzBitBtn;
tsgFields: TtsDBGrid;
procedure btConfirmClick(Sender: TObject);
procedure btCancelClick(Sender: TObject);
private
{ Private declarations }
public
FieldsList:TStringList;
_Count:integer;
end;
var
FrmFields: TFrmFields;
implementation
{$R *.dfm}
procedure TFrmFields.btConfirmClick(Sender: TObject);
var
iLoop,jLoop:integer;
begin
_count:=0;
FieldsList:=TStringList.Create;
try
for iLoop:=1 to tsgFields.Rows do
if tsgFields.Cell[1,iLoop]<>'' then
begin
for jLoop:=1 to tsgFields.Cols do
FieldsList.Add(tsgFields.Cell[jLoop,iLoop]);
_count:=_count+1;
end;
finally
//FieldsList:=nil;
//FieldsList.Free;
end;
ModalResult:=mrOK;
end;
谢谢!谢谢!