当前位置:主页>销售管理软件> 列表

为什么使用FindComponent(QRLabel 找erp软件

库存管理软件版1楼: 我想动态控制多个QRLabel控间的属性,我得代码是:
var
Cmp1: TComponent;
begin
....
for i:= 1 to 6 do
begin
Cmp1 := FindComponent(''QRLabel'' + IntToStr(i));
end;
每次执行完之后cmp1都是nil,可是我得界面里面有QRLabel1~QRLabel6这个控件

2楼: QRLabel1是动态创建的吗?
属主是Self吗 如果是Application的 那么的要用Application.FindComponent 如p3项目管理软件下载

3楼: 我得QRLabel不是动态创建的,是直接在界面上创建的

4楼: 你的代码是写在报表单元里面的吗?

5楼: 是写在报表单元里的

6楼: (QRLabel1.Parent).FindComponent

QRLabel1也可以使用在同一容器内其他可见控件代替

库存管理软件版7楼: 不行,返回值还是nil

8楼: 确定那些控件没有被改名称?

9楼: Cmp1 := FindComponent(''QRLabel'' + IntToStr(i)) as TQRLabel

10楼: 这些控间没有被改名字,而且我用cmp1 := FindComponent(''QRLabel1'');返回的值都是nil,请大家帮帮忙看看是什么问题,在线等,谢谢

11楼: 我测试了一下,如下代码是能找到的!
procedure TQuickReport2.QuickRepBeforePrint(Sender: TCustomQuickRep;
var PrintReport: Boolean);
begin
if FindComponent(''QRLabel1'') <> nil then
ShowMessage(''Found!'');
end;

12楼: 自己看看源码
function TComponent.FindComponent(const AName: string): TComponent;
var
I: Integer;
begin
if (AName <> '''') and (FComponents <> nil) then
for I := 0 to FComponents.Count - 1 do
begin
Result := FComponents[I];
if SameText(Result.FName, AName) then Exit;
end;
Result := nil;
end;
下面也是动态控制多个控件得
for I := 0 to 2 do
begin
List := FindComponent(''ListBox'' + IntToStr(HeaderControl1.Sections[I].ImageIndex)) as TListBox;
List.Left := HeaderControl1.Sections[I].Left;
List.Width := HeaderControl1.Sections[I].Width;
end; 如erp软件

13楼: 能再说明白点吗?

库存管理软件版14楼: 问题解决了,原来是因为我把这些写到了with dataset do里面了,而dataset本身就带有FindComponent方法,所以执行的时候返回值为空,谢谢大家了