Solved

How to create a DATASOURCE property

Posted on 1997-06-03
7
270 Views
Last Modified: 2010-04-06
I want to know how to create a datasource property in an own written component and to access the datasource, that means how to get the data from ttable or tquery ?
0
Comment
Question by:angerer
  • 3
  • 3
7 Comments
 
LVL 2

Expert Comment

by:icampbe1
ID: 1336774
Declare a PROPERTY  of type TDataSource in your component.  Make if reference a private field like FDataSource: TDataSource.  In the components constructor, create the DataSource object, and be sure to free it in the component's destructor.  You can then use the properties and methods of your DataDource property to do whatever you want.

0
 
LVL 1

Author Comment

by:angerer
ID: 1336775
I am sorry but this is the stand of information i had before too. The documentation on this problem is not very good (or i am blind) and therefore i do not know how to access the data with this FDataSource.
It would be wonderfull if you have some code example and can help me with that.

Anyway - thank you very much

DI Bernhard Angerer
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1336776
Yes, It Works!  I'm not sure what you don't understand.

TYPE
   TAngerer = CLASS( Whatever )
   PRIVATE
     FDSource: TDataSource;
   PUBLIC
     CONSTRUCTOR Create(...);    {<---THis is up to you}
     DESTRUCTOR Destroy;   Override;
     PROPERTY DataSource: TDataSource  Read FDSource;
   END;

IMPLEMENTATION

CONSTRUCTOR TAngerer.Create(...):
BEGIN
   FDSource := TDataSource.Create( Self );
END;

DESTRUCTOR TAngerer.Destroy;
BEGIN
   FDSource.Free;
END;

Now, use your object....

XX ;= TAngerer.Create(....);
XX.DataSource := SomeTTable;  {Or whatever}

I hope this is more clear!

Ian C.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:angerer
ID: 1336777
Thank you very much for your efford but,
let us inherit TAngerer from TEdit and please show me how i can assign the Text property with let as say the NAME column from the table ANIMALS.DBF (example table from delphi). In the text field should than appear 'Angel Fish' when the cursor is standing on the first position.

Thanks
bernhard
0
 

Accepted Solution

by:
brittain earned 100 total points
ID: 1336778
I'll assume you're trying to create a data-aware control.  

If so, you should check the Delphi docs & source for TFieldDataLink.  This is the class which actually does the data access.  In your class, the Datasource property is just a string.

Example from the source (TDBEdit):

constructor TDBEdit.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  inherited ReadOnly := True;
  ControlStyle := ControlStyle + [csReplicatable];
  FDataLink := TFieldDataLink.Create;
  FDataLink.Control := Self;
  FDataLink.OnDataChange := DataChange;
  FDataLink.OnEditingChange := EditingChange;
  FDataLink.OnUpdateData := UpdateData;
end;

function TDBEdit.GetDataSource: TDataSource;
begin
  Result := FDataLink.DataSource;
end;

procedure TDBEdit.SetDataSource(Value: TDataSource);
begin
  FDataLink.DataSource := Value;
  if Value <> nil then Value.FreeNotification(Self);
end;

Clearly there is other code you need.  But not much.  I recommend Ray Konopka's book on developing custom controls, but the docs have a partial example.

Scott



0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1336779
I'm sorry, I thought you said that you wanted to use a datasource within a control and perhaps to access a ttable from there.  I didn't know that you wanted to know how to make a control data aware.

Ian C.

0
 
LVL 1

Author Comment

by:angerer
ID: 1336780
Thank you...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 210
Copy file in dll not working but working on exe ! 18 88
Mydac connection data base issue 3 139
Multiple image collision 13 69
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now