Solved

How to detect form chansges?

Posted on 2000-02-20
6
204 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
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now