Solved

How to create a DATASOURCE property

Posted on 1997-06-03
7
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month6 days, 17 hours left to enroll

622 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