Solved

Writing code refering to a Ttable on a form from a custom component

Posted on 2003-10-22
5
213 Views
Last Modified: 2010-04-05
I am wondering if it is posible to write code refering to a specific Ttable on a form in a custom component.  I am trying to write code on the onClick and onContextPopup event of a customised TLabel and TImage so a user can access a database from a dynamically created Image and label that have being created on the OnMouseUp event of the form.  
I am using delphi 5.
Hope this makes sence
Thanks

Graeme
0
Comment
Question by:KiwiGraeme
[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
5 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 84 total points
ID: 9597384
?

....
procedure TForm1.MyPredefinedOnClick(Sender : TObject);
begin
  //whatever needed here
end;

procedure TForm1.MyPredefinedOnContextPopUp(Sender : TObject; MousePos: TPoint;
  var Handled: Boolean););
begin
  //whatever needed here
end;


....
Procedure TForm1.CreateLabel;
begin
  with Tlabel.Create(self) do
  begin
    top := WhatEver;
    left := WhatEver;
    parent := self;
    OnClick := MyPredefinedOnClick;
    OnContextPopUp := MyPredefinedOnContextPopUp;
    //...maybe more
  end;
end;
...


meikl ;-)

0
 
LVL 6

Assisted Solution

by:swift99
swift99 earned 83 total points
ID: 9597446
It is generally bad to break encapsulation.

If you really need to talk to the TTable component then ensure that the table is exposed as a property on the custom component.  From there on it's just like any other variable.

What you are suggesting is very straightforward.  meikl gave you most of what you need.
0
 
LVL 23

Assisted Solution

by:Ferruccio Accalai
Ferruccio Accalai earned 83 total points
ID: 9597928
BTW, if you're going to create these cmp dinamically maybe you need some differents procedures for every one...
And also you can have more than a Dataset on your form that must be linked to the cmps...

So an example to code these customized components should be this:

unit MyLabelAndImage;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, StdCtrls,db,extctrls;

type
  TLabel1 = class(TLabel)
  private
  fDataset: TDataset; //so you can use all TDataset descendents (ADO, IB, BDE...)
    { Private declarations }
  protected
    { Protected declarations }
    procedure Click; Override;
  public
    { Public declarations }
  published
    { Published declarations }
    property Dataset: TDataset read fDataset write fDataset;
  end;
  TImage1 = class(TImage)
  private
  fDataset: TDataset;
 
    { Private declarations }
  protected
    { Protected declarations }
    procedure DoContextPopup(MousePos: TPoint; var Handled: Boolean); override;
   
  public
    { Public declarations }
  published
    { Published declarations }
    property Dataset: TDataset read fDataset write fDataset;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Standard', [TLabel1,TImage1]);
end;
procedure TLabel1.Click;
begin
      inherited;
      if Assigned(fDataset) then
         caption := fDataset.Name;//just an example
   
end;
procedure TIMAGE1.DoContextPopup(MousePos: TPoint; var Handled: Boolean);
begin
      Inherited;
   if Assigned(fDataset) then
         Messagebox(0,PCHAR(Fdataset.name),PCHAR('Info'),0);//just an example
end;    
end.

F68 ;-)
0

Featured Post

[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.

Question has a verified solution.

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

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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month8 days, 17 hours left to enroll

615 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