procedure TDocProperty.CreateComponentsArr(TypeID:String);
var
lQuery:TQuery;
ArrCompHeight:Array of Integer; //保存该组件数组每个组件的高度+间距
CompName,LabelName,MustFlag:String;
NowTop,i,j,LabelHeight:integer;
cEdit:TEdit;
cDateEdit:TDateEdit;
cMemo:TMemo;
cLabel:TLabel;
begin
FreeComponentsArr;
CompName:='Comp';
LabelName:='Label';
i:=CompIndexBase;
j:=LabelIndexBase; //Label名称后缀和初始索引值
LabelHeight:=17; //Label的高度+间距
NowTop:=TopBase+LabelHeight;
lQuery:=TQuery.Create(nil);
try
lQuery.ConnectionString:=cConnectionString;
lQuery.CommandText:='SELECT FT_TypeField,FT_TypeFieldClass,FT_Must FROM FILETYPE'
+' WHERE FT_TypeID='''+TypeID+''' ORDER BY FT_FieldOrder';
lQuery.Open;
if not lQuery.IsEmpty then
begin
NowFieldCount:=lQuery.RecordCount;
SetLength(ArrCompHeight,NowFieldCount);
if (NowFieldCount=1) and
lQuery.FieldByName('FT_TypeField').AsString.Equals('') then
begin
NowFieldCount:=0;
Exit;
end;
While not lQuery.Eof do
begin
if lQuery.FieldByName('FT_TypeFieldClass').AsString.Equals(DateField) then
begin
cDateEdit:=TDateEdit.Create(Self);
cDateEdit.Name:=CompName+SysUtils.IntToStr(i);
cDateEdit.ComponentIndex:=i;
cDateEDit.Visible:=False;
cDateEdit.Parent:=GroupBox3;
cDateEdit.Top:=NowTop;
cDateEdit.Left:=CompLeftBase;
cDateEdit.Width:=CompWidth;
cDateEdit.Ctl3D:=False;
NowTop:=NowTop+cDateEdit.Height+Space+LabelHeight;
ArrCompHeight:=cDateEdit.Height+Space;
end else
if lQuery.FieldByName('FT_TypeFieldClass').AsString.Equals(MemoField) then
begin
cMemo:=TMemo.Create(Self);
cMemo.Name:=CompName+SysUtils.IntToStr(i);
cMemo.ComponentIndex:=i;
cMemo.Visible:=False;
cMemo.Parent:=GroupBox3;
cMemo.Text:='';
cMemo.Top:=NowTop;
cMemo.Left:=CompLeftBase;
cMemo.Width:=CompWidth;
cMemo.BorderStyle:=TFormBorderStyle.bsNone;
cMemo.BevelInner:=TBevelCut.bvNone;
cMemo.BevelKind:=TBevelKind.bkFlat;
NowTop:=NowTop+cMemo.Height+Space+LabelHeight;
ArrCompHeight:=cMemo.Height+Space;
end else
begin
cEdit:=TEdit.Create(Self);
cEdit.Name:=CompName+SysUtils.IntToStr(i);
cEdit.ComponentIndex:=i;
cEdit.Visible:=False;
cEdit.Parent:=GroupBox3;
cEdit.Text:='';
cEdit.Top:=NowTop;
cEdit.Left:=CompLeftBase;
cEdit.Width:=CompWidth;
cEdit.Ctl3D:=False;
NowTop:=NowTop+cEdit.Height+Space+LabelHeight;
ArrCompHeight:=cEdit.Height+Space;
end;
i:=i+1;
lQuery.Next;
end;
NowTop:=TopBase;
lQuery.First;
While not lQuery.Eof do //初始化Label控件数组
begin
cLabel:=TLabel.Create(Self);
cLabel.Name:=LabelName+SysUtils.IntToStr(j);
cLabel.ComponentIndex:=j;
cLabel.Visible:=False;
cLabel.Parent:=GroupBox3;
cLabel.Top:=NowTop;
cLabel.Left:=LabelLeftBase;
if lQuery.FieldByName('FT_Must').AsString.Equals('1') then
MustFlag:=' *'
else
MustFlag:='';
cLabel.Caption:=lQuery.FieldByName('FT_TypeField').AsString+MustFlag;
NowTop:=NowTop+cLabel.Height+Space+ArrCompHeight[j-LabelIndexBase];
j:=j+1;
lQuery.Next;
end;
for i:=0 to NowFieldCount-1 do //全部创建完成后统一显示
begin
if (Components is TEdit) then
(Components as TEdit).Visible:=True
else if (Components is TDateEdit) then
(Components as TDateEdit).Visible:=True
else if (Components is TMemo) then
(Components as TMemo).Visible:=True;
if (Components[i+LabelIndexBase] is TLabel) then
(Components[i+LabelIndexBase] as TLabel).Visible:=True;
end;
if NowTop>500 then
begin
GroupBox3.Height:=NowTop+89+20; //89为最大控件TMemo的高度
end else
begin
GroupBox3.Height:=524;
end;
end;
finally
lQuery.Free;
end;
end; |