A simple question?

I hate global variables.  They have their uses but I try and avoid them like
the plague if I can.

What I want to do is open a form with and pass it the ID of a record from a
table so that it will show only that record.

I do it like this now

  NoteID := DBGrid2.SelectedField.asString; // where NoteID is a global
variable

  Application.CreateForm(TNoteForm, NoteForm);
  NoteForm.ShowModal;
  NoteForm.Free;

when NoteForm opens it runs this...

procedure TNoteForm.FormCreate(Sender : TObject);
  Query1.SQL.Clear;
  Query1.SQL.Add('SELECT * FROM NOTES WHERE NOTEID = :NOTEID');
  Query1.Params[0].asString := NoteID; // that Global variable
  Query1.Open;

etc.

I can do it like this 

  Application.CreateForm(TNoteForm, NoteForm);
  NoteForm.Label11.Caption := DBGrid2.SelectedField.asString;
  NoteForm.ShowModal;
  NoteForm.Free;

but this means I have an invisible label sitting on my form.  Messy.

I have tried...

  Application.CreateForm(TNoteForm, NoteForm);
  NoteForm.NoteID := DBGrid2.SelectedField.asString;
  NoteForm.ShowModal;
  NoteForm.Free;

***

unit UNoteForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask, DBCtrls, Db, DBTables, Main, ComCtrls, PGlobal;

type
  TNoteForm = class(TForm)
    Label1: TLabel;
    ....
    procedure FormCreate(Sender: TObject);
    ....
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  NoteForm  : TNoteForm;
  NoteID    : String;

doesn't work...


I am sure this is really simple and probably a basic concept in Delphi but I
have never been able to quite get it.

Thanks in advance,

Steve
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to