MyTable adding a method

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
777Yves
Posts: 37
Joined: Mon 09 Aug 2010 19:55
Location: Québec

MyTable adding a method

Post by 777Yves » Tue 04 Jan 2011 15:52

Hi, I am migrating a Delphi 5 application to Delphi XE.
I also migrate the Dbase data to MySql.
I have a MyDac 6 Pro licence.

To make the migration smoother, I want to add a method to MyTable to simulate a seek. I have try with the Delphi class explorer but without succes.

How could I do that ?
What do I need to do that ?

Thanks
Yves.

AndreyZ

Post by AndreyZ » Wed 05 Jan 2011 12:21

Hello,

You can inherit your own table class from the TMyTable class and add a new method in the following way:

Code: Select all

TNewMyTable = class(TMyTable)
public
  procedure NewMethod;
end;

procedure TNewMyTable.NewMethod;
begin
//your code
end;

777Yves
Posts: 37
Joined: Mon 09 Aug 2010 19:55
Location: Québec

Ok

Post by 777Yves » Wed 05 Jan 2011 15:48

Hi, I understand what you do, no problem.
When I drop the component TMyTable in a unit, it create an instance of TMyTable not from the new Class I just create as in your example.
So the compiler complain.
[DCC Erreur] SDIMAIN.PAS(56): E2003 Identificateur non déclaré : 'seek'

I have try this other way to do what I want and it seem to work well.
This is just a fast testing but it work.

Thanks

Code: Select all

unit SDIMAIN;

interface

uses Windows, Classes, Graphics, Forms, Controls, Menus,
  Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls, ImgList, StdActns,
  ActnList, ToolWin, Grids, DBGrids, CRGrid, DB, DBAccess, MyAccess, MemDS;

type
  TSDIAppForm = class(TForm)
    MyConnection1: TMyConnection;
    MyDataSource1: TMyDataSource;
    CRDBGrid1: TCRDBGrid;
    Label1: TLabel;
    Label2: TLabel;
    MyTable1: TMyTable;
    procedure FileExit1Execute(Sender: TObject);
    procedure Label2Click(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

  TMyyTable = class helper for TMyTable
  //TMyyTable = class(TMyTable)
  public
    function Seek(LeFiltre: String): Boolean;
  end;

var
  SDIAppForm: TSDIAppForm;

implementation

uses about;

{$R *.dfm}

function TMyyTable.Seek(LeFiltre: String): Boolean;
begin
  Self.FilterSQL := LeFiltre;
  if Self.RecordCount = 0 then
    Result := false
  else
    Result := True;
end;

procedure TSDIAppForm.FileExit1Execute(Sender: TObject);
begin
  Close;
end;

procedure TSDIAppForm.Label2Click(Sender: TObject);
begin
  MyTable1.seek('Perma = 1017274');
end;

end.

AndreyZ

Post by AndreyZ » Thu 06 Jan 2011 10:56

You've found a good solution.

Post Reply