PDA

View Full Version : save کردن فرم در runtime



msproud2001
شنبه 03 دی 1384, 08:42 صبح
با سلام
اگر بخوام یک فرم رو با همه ی محتویاتش در زمان اجرا (runtime) ذخیره کنم باید دقیقا چی کار کنم

ali_abbasi22145
شنبه 03 دی 1384, 14:49 عصر
سلام
کار کمی سخت است اما من برنامه نوشتم که بعد اجرای برنامه کاربر می تواند فرم راتغییر داده و فیلدها و لیبلها و...
را تغییر دهد یعنی فرم داینامیک کامل اما خشکه حساب می کنم!

Babak-Aghili
سه شنبه 06 دی 1384, 01:40 صبح
با سلام
اگر بخوام یک فرم رو با همه ی محتویاتش در زمان اجرا (runtime) ذخیره کنم باید دقیقا چی کار کنم

TStream و بهترش TMemoryStream ، یک خاصیتی داره بنام WriteComponent که مثلا میشه اینجوری نوشت و نتیجه را در یک فایل ذخیره کرد ... بدیهی ست که بعدا میشه Load ش هم کرد .. :چشمک:


myMemoryStream.WriteComponet ( Form1);

این تئوری بود .. من امتحان نکردم ... ولی فکر کنم از این راه بشه .
شاید فردا شب وقت شد امتحان کردم . :لبخندساده

روی همین ایده کار کن .......

Babak-Aghili
چهارشنبه 21 دی 1384, 16:48 عصر
اینطوری میتونی کامپوننت های فرم را جابجا کنی و دفعه ی بعد که فرم لود شد ، در جای جدید قرار خواهند داشت . :لبخند: برای مثال توی کد زیر ، یک edit , listbox, combobox پیش بینی شده ...







unit Main;

interface

uses
Windows,WinProcs, Messages, SysUtils, Classes,
Graphics, Controls, Forms, Dialogs, StdCtrls, Menus,
registry;

type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
ListBox1: TListBox;
ComboBox1: TComboBox;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure AppMessage(var Msg: TMsg;
var Handled: Boolean);
public
{ Public declarations }
end;

const
SC_SIZE = $F012;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
iTemp: Integer;
r : TRegIniFile;
begin
(* Open the key in the registry where we store
all the positions *)
r := TRegIniFile.Create('Resize Test');

(* Loop through all the components on a form *)
for iTemp := 0 to ComponentCount -1 do
(* Get the position of all controls *)
if Components[iTemp] is TControl then
with Components[iTemp] as TControl Do
begin
left:=r.readinteger(Name,'Left',left);
top:=r.readinteger(Name,'Top',Top);
(* Make there cursors crosses *)
cursor:=crCross;
end;
(* Release the registry object *)
r.free;

(* Use our own message handler for all message
sent to the application *)
Application.OnMessage := AppMessage;
end;

procedure TForm1.AppMessage(var Msg: TMsg;
var Handled: Boolean);
begin
(* Only do anything if the left mouse button is
pressed *)
if msg.message = wm_LBUTTONDOWN then
begin
(* Release the mouse capture *)
WinProcs.ReleaseCapture;
(* Send a message to the control under the
mouse to go into move mode *)
postmessage ( msg.hwnd,WM_SysCommand, SC_SIZE, 0 );
(* Say we have handled this message *)
Handled:=true;
end;
end;


procedure TForm1.FormDestroy(Sender: TObject);
var
iTemp: Integer;
r : TRegIniFile;
begin
(* As in the form create loop through all the
components But this time write the left and
top properties to the registry *)

r := TRegIniFile.Create('Resize Test');
for iTemp := 0 to ComponentCount -1 do
if Components[iTemp] is TControl then
with Components[iTemp] as TControl Do
begin
r.writeinteger(Name,'Left',left);
r.writeinteger(Name,'Top',Top);
end;
r.free;
end;
end.
میشه یک فلگ هم درنظر گرفت ... مثلا اینطوری :

If fDesigning then
Application.OnMessage := AppMessage
else
Application.OnMessage := nil;