Thread: Searching form

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Searching form


    hi this is my first application with delphi but i cant find out how to deal with master detail forms i mean i have a master form . what i want to do is when i click to search button ....search form supposed to be pop up.but nothing happens .tis code is not enough what else should i do

    [CODE]
    procedure TfrmMain.Button2Click(Sender: TObject);
    var
    s:string;
    i:Integer;

    begin
    Application.CreateForm(Tfrmsearch, frmsearch);
    s:=frmsearch.Edit1.Text;
    for i:=0 to FileSize(fileCustomer)-1 do
    begin
    Seek(fileCustomer,i);
    Read(fileCustomer,customer);
    if Trim(s)=Trim(customer.company) then
    begin
    end;


    end;

    end;



    CODE]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    354
    Rep Power
    7
    First off, you don't want to call Application.CreateForm.

    What you can do is declare a new constructor method for your detail form (frmSearch), and pass it the information your child form needs to search for the desired record. Also, rather than use a TTable component and do a Seek, you could use a TQuery, and open the query with the passed in parameter.

    So, in frmSearch, you need to add two declarations to the form's declaration.

    Code:
    TfrmSearch = class(TForm)
      ...
      private
         PassedInParam: String; //or whatever type it should be
         ...
      public
         constructor CreateSearchForm(MyParameter: String);
          //MyParameter needs to be the same type as PassInParam
         ...
      end;
    then your constructor would look like:
    Code:
    constructor TfrmSearch.CreateSearchForm(MyParameter: String);
    begin
       Inherited Create(Application);
       PassedInParam := MyParameter;
       //set the private form variable to the passed in value
    end;
    Then add an OnFormCreate Event for the TFrmSearch
    Code:
    procedure TfrmSearch.FormCreate(Sender: TObject);
    begin
      ...
      //if you use the TQuery Method I mentioned, then set the parameter
      TQueryX.ParamByName('ParamCustomerName').AsString := PassedInParam;
      //set the parameter to the private field PassedInParam's Value
      TQueryX.Open;
    end;
    TQuery.SQL.Text would look something like
    Code:
    Select <Column1>, .., <ColumnN>
    From <TableName>
    Where fileCustomer = :ParamCustomerName
    Make sure you also free the memory associated with this form in the OnClose event
    Code:
    procedure TfrmSearch.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action := caFree;
    end;
    In TFrmMain, make sure frmSearch's unit is in uses clause, and you would call it like so:
    Code:
    procedure TfrmMain.Button2Click(Sender: TObject);
    var
       NewSearchForm: TFrmSearch;
       CustomerName: String;
    begin
       CustomerName := 'Customer X';
       NewSearchForm := TFrmSearch.CreateSearchForm(CustomerName);
    end;
    Last edited by majlumbo; August 31st, 2012 at 08:31 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0
    Hi friend and thanks for repliyng me i it works now thanks a lot
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    354
    Rep Power
    7
    Glad it helped!!

IMN logo majestic logo threadwatch logo seochat tools logo