• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

How to detect form chansges?

Hello,

I have many TEdit and TDBCombo components on my form. Say I want to
detect (on form close) whether any of them were changed (not just
clicked), what would be the proper way to do this?

Thank you
Fatima
0
ffelaar
Asked:
ffelaar
1 Solution
 
intheCommented:
well if you dont want to use normal onchange event and only want to know on form close then maybe you can use a ini file to set whatever it is that you are doing when the components change.
on formcreate read the ini to set the components states etc and write states back to ini on form close.

if need example code just ask.
0
 
ZifNabCommented:
yup, think this is the only way to do it
0
 
intheCommented:
here an example of using ini file to save and load various types of component settings:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,IniFiles, ComCtrls;

type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    CheckBox3: TCheckBox;
    Edit1: TEdit;
    TrackBar1: TTrackBar;
    Edit2: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  IniFile : TIniFile;
implementation

{$R *.DFM}

procedure TForm1.FormDestroy(Sender: TObject);
begin
IniFile:=Tinifile.Create('c:\myini.ini');
inifile.WriteBool('Checkboxes','CheckBox1',Checkbox1.Checked);
inifile.WriteBool('Checkboxes','CheckBox2',Checkbox2.Checked);
inifile.WriteBool('Checkboxes','CheckBox3',Checkbox3.Checked);
IniFile.WriteString('Edits_Text','Edit1',Edit1.Text);
IniFile.WriteString('Edits_Text','Edit2',Edit2.Text);
IniFile.WriteInteger('TrackBars','TrackBar1',Trackbar1.Position);
InIfile.Free;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
IniFile:=Tinifile.Create('c:\myini.ini');
Checkbox1.Checked := Inifile.ReadBool('Checkboxes','Checkbox1',False);
Checkbox2.Checked := Inifile.ReadBool('Checkboxes','Checkbox2',False);
Checkbox3.Checked := Inifile.ReadBool('Checkboxes','Checkbox3',False);
Edit1.Text := IniFile.ReadString('Edits_Text','Edit1','');
Edit2.Text := IniFile.ReadString('Edits_Text','Edit2','');
TrackBar1.Position := IniFile.ReadInteger('TrackBars','TrackBar1',0);
IniFile.Free;
end;

end.

if you mainly using edits and dblookups then the main one you be using is writestring('Lookup1','DBLookupCombobox1',bdlookupcombobox1.Text);
but i think this is good example to show for checkboxes etc too so you see of how to use writebool ,writeinteger etc..

let us know if this is help.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tonnybrandtCommented:
Assuming you want to know if any of them has changed, not exactly which one.
How about the modified property.
Something like this:

Changed := False;
For i := 0 to componentcount -1 do
   begin
   if components[i] is TEdit then
      if Tedit(components[i]).modified then
         changed := True;
   if components[i] is TDBCombo then
      if TDBCombo(components[i]).modified then
         changed := True;
   end;
If Changed then ...........

(i don't know for sure if TDBCombo has the modified property)
Good luck
0
 
florisbCommented:
set property tag in change / click or whatever events that you can happen with.your components. You van also do all the detection in the FormClose I think?

If using an ini-file: consider the registry. See help, easy.

In formclose:

PSEUDOCODE!

for x := 0 to form1.componentcount -1 do
  if form1.components[x] is tedit then
    if tedit(form1.components[x]).tag <> 0 then
  begin
  case tedit(form1.components[x]).tag is
  // this component is changes, do something with if.
    0: //nothing
    1: //changed
    2: //deleted
  end;


Floris.


 
0
 
ffelaarAuthor Commented:
Thank you Inthe ...

It is the best solution to my problem that I have gotten from anyone. I appreciate it.

Kind regards,
ffelaar
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now