Solved

How to create a DATASOURCE property

Posted on 1997-06-03
7
273 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
Help on project with Soap 10 62
Correct Component for Shopping Cart. 2 121
Delphi: making a BW image transparent 10 91
Browsing a TTreeView in Delphi 5 32
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 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