CnPack Forum


 
Subject: 不可视组件的Top和Left
sonicer
新警察
Rank: 1


UID 677
Digest Posts 0
Credits 48
Posts 18
点点分 48
Reading Access 10
Registered 2005-2-1
Status Offline
Post at 2010-4-16 18:03  Profile | Blog | P.M. 
不可视组件的Top和Left

系统带的非可视组件放到窗体上后然后保存,下次再打开这个窗体,非可视组件就出现在上次放置的位置(废话了,这功能当然谁都知道)
这实际上意味着非可视组件也有位置属性保存起来了,实际上打开dfm文件,所有的组件都有left=xxx top=xxx的字样

非可视组件使用了一种特殊方式来保存这两个值,

我想问一下,如何在程序中读到这两个值?

谢谢
Top
zjy
管理员
Rank: 9Rank: 9Rank: 9



UID 2
Digest Posts 6
Credits 2385
Posts 1543
点点分 2385
Reading Access 102
Registered 2002-12-16
Location China
Status Offline
Post at 2010-4-16 21:23  Profile | Site | Blog | P.M. 
从 Classes.pas 中可以找到:

procedure TComponent.ReadLeft(Reader: TReader);
begin
  LongRec(FDesignInfo).Lo := Reader.ReadInteger;
end;

procedure TComponent.ReadTop(Reader: TReader);
begin
  LongRec(FDesignInfo).Hi := Reader.ReadInteger;
end;

procedure TComponent.DefineProperties(Filer: TFiler);
var
  Ancestor: TComponent;
  Info: Longint;
begin
  Info := 0;
  Ancestor := TComponent(Filer.Ancestor);
  if Ancestor <> nil then Info := Ancestor.FDesignInfo;
  Filer.DefineProperty('Left', ReadLeft, WriteLeft,
    LongRec(FDesignInfo).Lo <> LongRec(Info).Lo);
  Filer.DefineProperty('Top', ReadTop, WriteTop,
    LongRec(FDesignInfo).Hi <> LongRec(Info).Hi);
end;

显然,DesignInfo 里面保存的就是你要的东西。




Zhou JingYu
CnPack Administrator
http://www.cnpack.org/
Top
sonicer
新警察
Rank: 1


UID 677
Digest Posts 0
Credits 48
Posts 18
点点分 48
Reading Access 10
Registered 2005-2-1
Status Offline
Post at 2010-4-17 17:29  Profile | Blog | P.M. 
这段代码当时走马观花,人懒,总以为有类似于object.left之类的方法来读取,没想到用这种办法
多谢领导
Top
 




All times are GMT++8, the time now is 2024-11-22 23:36

    本论坛支付平台由支付宝提供
携手打造安全诚信的交易社区 Powered by Discuz! 5.0.0  © 2001-2006 Comsenz Inc.
Processed in 0.006886 second(s), 7 queries , Gzip enabled

Clear Cookies - Contact Us - CnPack Website - Archiver - WAP