Page 1 of 1
					
				Syntax for retreiving data.
				Posted: Sat  01 Aug 2015 03:03
				by marsheng
				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
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Sun  02 Aug 2015 13:43
				by davidmarcus
				You can't cast the name (a string) to a field. Something like
MemEdit.Text := MyTable.FieldByName( "FieldName" ).AsString;
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Mon  03 Aug 2015 05:21
				by marsheng
				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.
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Mon  03 Aug 2015 08:20
				by ViktorV
				This question concerns to principles of working with the TDataSet standard class. To resolve it, please refer to the Embarcadero documentation.
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Tue  04 Aug 2015 11:39
				by marsheng
				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..
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Tue  04 Aug 2015 13:23
				by ViktorV
				You can implement the needed functionality using the following code.
var
 MyTable: TMyTable;
...
MyTable.TableName := 'TableName';
MyTable.Open;
MemEdit.Text := MyTable.FieldByName('FieldName').AsString;
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Wed  05 Aug 2015 11:53
				by marsheng
				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.
 
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Wed  05 Aug 2015 12:13
				by davidmarcus
				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.
			 
			
					
				Re: Syntax for retreiving data.
				Posted: Wed  13 Apr 2016 07:34
				by ViktorV
				Before using an object, you should create it first. To solve the issue, please add the following code line: 
before the line: