Solved

How to detect form chansges?

Posted on 2000-02-20
6
213 Views
Last Modified: 2012-06-21
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
Comment
Question by:ffelaar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2539492
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 2539518
yup, think this is the only way to do it
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 2539578
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
Independent Software Vendors: 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!

 
LVL 10

Expert Comment

by:tonnybrandt
ID: 2539801
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
 
LVL 2

Expert Comment

by:florisb
ID: 2539988
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
 

Author Comment

by:ffelaar
ID: 2552359
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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working with hours 3 86
Base1 Encode/Decode 3 98
Delphi problems to abort a printjob 9 47
FMX TEdit KeyUp handler detecting  "enter" key 4 61
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question