Solved

How to detect form chansges?

Posted on 2000-02-20
6
207 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 196
code issue 8 126
Help on project with Soap 10 52
How do I add a client SSL certificate to a SOAP client in Rad Studio Delphi? 2 68
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…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

815 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

11 Experts available now in Live!

Get 1:1 Help Now