/*********激烈討論,認為對Delphi很熟的高手們請進,想學習的也快進來**********/ (200分)

  • 主题发起人 主题发起人 leway
  • 开始时间 开始时间
一样的,做一个界面,控件编辑属性。生成pas and dfm。
其实你想过没有,你的需求就是这些,解决方案如下。
1、 可以动态生成控件(这个不难啦)。
2。 编辑(运行期拖动控件位置,编辑width 等属性,
这个也不难,我写过拉)。
3。生成对应文件,这个就没意思啦,遍历一下你生成的控件把他们的属性
按照 pas 和 dfm的 规范写成文本就行啦。
又:
楼着这么做有什么意思??作一个自动生成代码的工具??
 
是啊,如果空间种类是固定的那就太简单了。
生成一个类似DFM的窗体文件,我建议最好是XML格式的。
1、從控件頁點選控件到窗體中。
通过窗体文件的内容创建控件。
2、能對窗體中的控件設置屬性。(控件的位置、大小、Caption、name等等)
根据窗体文件中的记录设置属性
3、窗體編輯完成後,存成文件。
保存窗体文件。
4、能從文件打開窗體。
设计时,由窗体文件装入。
我不知道这有什么可讨论的。
 
如果是动态调整TControl控件可以
procedure TForm1.ManipulateControl(Control: TControl; Shift: TShiftState;
X, Y, Precision: integer);
var
SC_MANIPULATE: Word;
begin
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最左侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (X <= Precision) and (Y > Precision) and
(Y < Control.Height - Precision) then
begin
SC_MANIPULATE := $F001;
Control.Cursor := crSizeWE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最右侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
if (X >= Control.Width - Precision) and (Y > Precision) and
(Y < Control.Height - Precision) then
begin
SC_MANIPULATE := $F002;
Control.Cursor := crSizeWE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最上侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
if (X > Precision) and (X < Control.Width - Precision) and
(Y <= Precision) then
begin
SC_MANIPULATE := $F003;
Control.Cursor := crSizeNS;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的左上角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else if (X <= Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F004;
Control.Cursor := crSizeNWSE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的右上角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
if (X >= Control.Width - Precision) and (Y <= Precision) then
begin
SC_MANIPULATE := $F005;
Control.Cursor := crSizeNESW;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的最下侧**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
if (X > Precision) and (X < Control.Width - Precision) and
(Y >= Control.Height - Precision) then
begin
SC_MANIPULATE := $F006;
Control.Cursor := crSizeNS;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的左下角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
if (X <= Precision) and (Y >= Control.Height - Precision) then
begin
SC_MANIPULATE := $F007;
Control.Cursor := crSizeNESW;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的右下角**********************************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
if (X >= Control.Width - Precision) and
(Y >= Control.Height - Precision) then
begin
SC_MANIPULATE := $F008;
Control.Cursor := crSizeNWSE;
end
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//光标在控件的客户区(移动整个控件)******************************************
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
else
if (X > 5) and (Y > 5) and (X < Control.Width - 5)
and (Y < Control.Height - 5) then
begin
SC_MANIPULATE := $F009;
Control.Cursor := crSizeAll;
end
else
begin
SC_MANIPULATE := $F000;
Control.Cursor := crDefault;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if Shift = [ssLeft] then
begin
ReleaseCapture;
Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);
end;
end;

然后调用不就行了:
procedure TForm1.DragControl(WinControl: TWincontrol);
const SC_DRAGMOVE = $F012;//如果为$F000-$F012还能调整大小
begin
ReleaseCapture;
WinControl.Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
end;


procedure TForm1.XXX控件MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DragControl(Panel1);
end;
属性编辑器,获得组件的属性列表
uses
Typinfo;

procedure ListComponentProperties(Component: TComponent; Strings: TStrings);
var
Count, Size, I: Integer;
List: PPropList;
PropInfo: PPropInfo;
PropOrEvent, PropValue: string;
begin
Count := GetPropList(Component.ClassInfo, tkAny, nil);
Size := Count * SizeOf(Pointer);
0A GetMem(List, Size);
try
Count := GetPropList(Component.ClassInfo, tkAny, List);
for I := 0 to Count - 1 do
begin
PropInfo := List^;
if PropInfo^.PropType^.Kind in tkMethods then
PropOrEvent := 'Event'
else
PropOrEvent := 'Property';
PropValue := VarToStr(GetPropValue(Component, PropInfo^.Name));
Strings.Add(Format(' s: s = s', [PropOrEvent, PropInfo^.Name,
PropInfo^.PropType^.Name, PropValue]));
end;
finally
FreeMem(List);
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.BeginUpdate;
Memo1.Lines.Clear;
ListComponentProperties(Button1, Memo1.Lines);
Memo1.Lines.EndUpdate;
0Aend;
注意,事件也是一种属性。它的类型是方法指针类型的。
真不明白有啥要讨论的必要?????
 
to: 人在昆明
你說的沒錯,我是在做一個代碼生成器。請提寶貴意見。
to: wr960204
你的代碼有些地方看不懂,如:ManipulateControl等是些什麼,誰來調用,代碼有些散,我看不出你的思路。麻煩解釋一下,謝謝。
to: Sachow
代碼收到,已調試通過。對我很有用。我正在讀你的代碼,不解的地方會問你。非常感謝!
 
我也曾经做过这一个东西:
首先建一个类似属性编辑器的窗体,里面有name,width,left,top等属性,并和
数据库关联(有个专门存放控件属性的表),
每次打开窗体时,都从库中读取控件的各属性,动态生成控件!
 
ManipulateControl不过就是一个方法的名称,要不然你直接写成函数也行
在你的控件的鼠标移动事件里调用
begin
ManipulateControl(TControl(Sender),Shift,X,Y,4);
end;
 
to: Sachow
非常謝謝你的Demo,決大部分已經看懂,有個小問題請教一下。
ActionList1: TActionList;
CreateSizeCtrl: TAction;
這兩個東西在程序中起何作用?

to: wr960204
ManipulateControl是控件的鼠标移动事件里调用,但的控件是動態創建的。那我每創建一個控件,就要把ManipulateControl附給OnMouseMove。這樣做可能有些麻煩。
DragControl由誰調用?

to: 雪中漫步
你提到的隻是保存控件屬性的一個方法,我要做的遠遠不止這些功能,我要做的是一個代碼生成器,第一步我要實現類似Delphi IDE
界面、控件編輯功能,後面的工作還有代碼輸出等工作。
 
ActionList1: TActionList;
CreateSizeCtrl: TAction;
动作列表,如同一个动作容器。
 
大家说得很透彻,我不用说了[:D]
 
To leway:关于那两个东东的用途,别人已经帮回答了。实际上你还可以找到其它的方法来
实现类似的功能,也许效果会更好哦(这程序是两年以前搞着玩的,之后一直没有深入研究)。

关于例程中的DelAllControl过程,建议作如下修改:
procedure TMF.DelAllControls; //删除窗体上的所有子控件
begin
While ComponentCount>0 do
Components[0].Free;
end;
 
這兩天一直沒有登陸成功,很抱歉沒有及時回應大家。
to: Sachow
ActionList1: TActionList;
CreateSizeCtrl: TAction;
這兩個東西在你的程序中隻有聲明,沒有看到在什麼地方用到過,所以要再次向你詢問一下。
 
兄弟,看没看过那个用delphi 写delphi ide 环境的例子,我有代码,不过太长
要不要去研究一下肯定能满足你的需求了吧!留个 有空间的箱子就行,我发给你!
 
to: 人在昆明
多謝,多謝!
有多大?發到Lyaip@etang.com
 
已经发拉,我象也就该结贴拉,发分吧。
 
多人接受答案了。
 
后退
顶部