Syntax for retreiving data.

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Syntax for retreiving data.

Post by marsheng » Sat 01 Aug 2015 03:03

I've tried many options but still no success.

How do I do this ? Take the contents from a Table Field and put it in and edit box.

tEdit(fMemEdit.FindComponent('eMasterMemName').Name).text:= TStringField(FindComponent('DM.tbl.MasterMemName').Name).AsString;

(DM is data module)
Thanks Wallace

davidmarcus
Posts: 50
Joined: Tue 25 Jan 2005 11:22
Location: Somerville, MA
Contact:

Re: Syntax for retreiving data.

Post by davidmarcus » Sun 02 Aug 2015 13:43

You can't cast the name (a string) to a field. Something like

MemEdit.Text := MyTable.FieldByName( "FieldName" ).AsString;

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: Syntax for retreiving data.

Post by marsheng » Mon 03 Aug 2015 05:21

Thanks for the reply. Almost there.
How do I achieve the following ?

table:='MyTable'
MemEdit.Text := table.FieldByName('FieldName').AsString;

I want to be able to dynamically retrieve data from a table.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Syntax for retreiving data.

Post by ViktorV » Mon 03 Aug 2015 08:20

This question concerns to principles of working with the TDataSet standard class. To resolve it, please refer to the Embarcadero documentation.

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: Syntax for retreiving data.

Post by marsheng » Tue 04 Aug 2015 11:39

I've tried various option and several Delphi local programmers but none seem to have a solution.

As this is a forum and not a support email, I hoping someone can shed some light on the matter.

Possibly I can use SQL statements to do the same thing?

I need to specify both the table and the field names in strings to retrieve the data..

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Syntax for retreiving data.

Post by ViktorV » Tue 04 Aug 2015 13:23

You can implement the needed functionality using the following code.
var
MyTable: TMyTable;
...
MyTable.TableName := 'TableName';
MyTable.Open;
MemEdit.Text := MyTable.FieldByName('FieldName').AsString;

marsheng
Posts: 62
Joined: Thu 10 May 2012 10:51

Re: Syntax for retreiving data.

Post by marsheng » Wed 05 Aug 2015 11:53

Something is not right. I get access violation error when I run this on the line eMasterMEMNAME.Text
If I comment out
tblName.TableName:='tblMaster' I don't have an error.

Code: Select all

var
   tblName: TMyTable;
begin
    tblName.TableName:='tblMaster';
    eMasterMEMNAME.Text:='Test';
   
Really confused now.

davidmarcus
Posts: 50
Joined: Tue 25 Jan 2005 11:22
Location: Somerville, MA
Contact:

Re: Syntax for retreiving data.

Post by davidmarcus » Wed 05 Aug 2015 12:13

You have to create the table object. Really, we can't help you unless you post your code. This is really a Delphi question, so you should post in the Embarcadero forums.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Syntax for retreiving data.

Post by ViktorV » Wed 13 Apr 2016 07:34

Before using an object, you should create it first. To solve the issue, please add the following code line:

Code: Select all

tblName := TMyTable.Сreate(nil);
before the line:

Code: Select all

tblName.TableName:='tblMaster';

Post Reply