Solved

data exchange between component and a Form

Posted on 2004-04-23
18
341 Views
Last Modified: 2010-04-05
Hi,
I wrote my first component:   MyComponent = Class (Tframe) ....;
a) This Component invokes  a  Form called TChildForm;  I can send data to the child form
with a function like ChildForm.SendData(Data: myData); But How to send Back the data
to the component. The Component is placed for debugging reason on a Form called MyParentForm.
Sending Back Data from the ChildForm to the Compenent goes at the moment like this
        MyParentForm.MyComponent.getdata(.....);
How th access the Component directly without using the Parent-Form  ?

b) Can i use property also for the Tframe-Class, just like a for "normal" component ?
regards
BdLM
     
0
Comment
Question by:BdLm
[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
  • 9
  • 9
18 Comments
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10900486
Add in your SendData function the variable for the component....
Like

Function SendData(Data: Mydata; var FromComponent: TMyComponent):...... assuming that TMyComponent is the type of your MyComponent

then Use FromComponent.GetData....

And this should be done also for TFrame i guess (don't know about the structure of your senddata and getdata procs)....
0
 
LVL 8

Author Comment

by:BdLm
ID: 10947217
still i get a run time error, i ' ll post more source code soon
0
 
LVL 8

Author Comment

by:BdLm
ID: 10948359
unit Unit_BitMapMidiClient;
{ The mdi-child, just contains the component  and nothing more...}

interface

type
  TMyMDIForm = class(TForm)
    DBitMap  : DClientFrame;

    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormResize(Sender: TObject);


   
  private

  public
    ID   : Integer;

  end;
--------------------------------------------------------------------------
unit SSCImageClientFrame;
{ the component, keeps all controls and the algorithms for bitmap manipulations }


type
  MidiModeOptions = (master,client);

  TDClientFrame = class(TFrame)
    MyPaintBox  : TPaintBox;
    xScrollBar  : TScrollBar;
    .....
  public
    { Public-Deklarationen }
    FrameBitMapData     : TParameterRecord; { a large data record }
    MyPointList         : TList;
    .....
end;

implementation

uses  ...., Unit_ServerParameter;



{******************************************************************************
 *  Edit The Data .....
 ******************************************************************************}
procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');

     ServerParameterForm.Init(FrameBitMapData, MyPointList);

     ServerParameterForm.ShowModal;
end;



--------------------------------------------------------------------------
unit Unit_ServerParameter;
{  the user dialog form, called from the component }

type
  TServerParameterForm = class(TForm)
  ....
  public
    { Public-Deklarationen }
    MyImageParameter     :  TParameterRecord;     { New Values  for Update and Changes }
    UndoImageParameter   :  TParameterRecord;     { If user want to make an Undo command }
    MyPointList          :  TList;
    UndoPointList        :  TList;


   
    procedure Init(ImageParameter  : TDisPlayBitMap; PointList :  TList);
  end;


procedure TServerParameterForm.Init(ImageParameter  : TDisPlayBitMap; PointList :  TList );
var    i   : Integer;
begin

         ....  // send the data to the FORM, called from the component , Works fine

end;


procedure TServerParameterForm.CloseBitBtnClick(Sender: TObject);
begin
      // Copy Back the Edited Data to the Component in the MDI Child

      MyMDIForm.DBitMap.FrameBitMapData := MyImageParameter;  <--  RUN TIME ERROR ???

      Close;
end;


what is the best way to send the data from the form back to the calling component ?
regards
BdLM

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 22

Expert Comment

by:Ferruccio Accalai
ID: 10948546
the runtime error is raised because you're passing the parameters from the component to the ServerParameterForm, but returning values to a component owned by the MDI that is unknowed by the original caller...

BTW as ServerParameterForm is a Modal Dialog Form you can do this:

procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');

     ServerParameterForm.Init(FrameBitMapData, MyPointList);

     ServerParameterForm.ShowModal;
     If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter;//these params must be accessible from TDClientFrame....
            etc...etc...
            ServerParameterForm.Free;
        end;
end;

and in ServerParameterForm.CloseBitBtnClick
ModalResult := mrOK;
end;

try this way and tell about it


0
 
LVL 8

Author Comment

by:BdLm
ID: 10949469
It works only once, recalling this code at a later step creates again an access vialoation
(writing to address .....)
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10949732
that could be because the line ServerParameterForm.Free;

As i can see there's not a Creation call into the EditBasicImageDataSet;

If so Add there:

If not Assigned(ServerParameterForm) then
//create the ServerParameterForm
ServerParameterForm.Init(FrameBitMapData, MyPointList);
     ServerParameterForm.ShowModal;
  etc..

or simply remove the above ServerParameterForm.Free;
In this case take care that the Init procedure passes the whole parameters correctly without letting some dirty values in SaveParameterForm from the last access....


0
 
LVL 8

Author Comment

by:BdLm
ID: 10950215
Ok, without ServerParameterForm.Free;
final Question:
If not Assigned(ServerParameterForm) then  
ServerParameterForm:=TServerParameterForm.create ??
0
 
LVL 8

Author Comment

by:BdLm
ID: 10950266
ServerParameterForm:=TServerParameterForm.create(nil) seems to be OK, but i should
exchange nil with the component , correct ?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10950296
@If not Assigned(ServerParameterForm) then  
ServerParameterForm:=TServerParameterForm.create ??


Yes, and it depends on wich must be the owner of the form:

You can create it owned by the application, so
ServerParameterForm:=TServerParameterForm.create(Application)

or simply create it with no Owner

ServerParameterForm:=TServerParameterForm.create(nil); that is the better way for me beacause you don't have to own any subcomponent of this form, but simply creatte it, use it and then destroy....
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10950400
ah, and just to be more correct this
    If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter
            etc...etc...
            ServerParameterForm.Free;
        end;
might be
procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');
     If not Assigned(ServerParameterForm) then  
        ServerParameterForm:=TServerParameterForm.create(nil);
     try
        If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter
            etc...etc...
         end;
     finally
        ServerParameterForm.Free;
     end;
end;
0
 
LVL 22

Accepted Solution

by:
Ferruccio Accalai earned 200 total points
ID: 10950414
sorry, missed the showmodal call :))

procedure TDClientFrame.EditBasicImageDataSet;
begin
     DisplayText(Panel_Warning,'please edit ViewPort and Pixel Size Data ...');
     If not Assigned(ServerParameterForm) then  
        ServerParameterForm:=TServerParameterForm.create(nil);
     try
        ServerParameterForm.ShowModal;
        If ServerParameterForm.ModalResult = mrOK then
        begin
            FrameBitMapData := ServerParameterForm.MyImageParameter
            etc...etc...
         end;
     finally
        ServerParameterForm.Free;
     end;
end;
0
 
LVL 8

Author Comment

by:BdLm
ID: 10987435
Hi,
i made a error and did all test with  \\ ServerParameterForm.Free;
Activating this code line the run time error occurs, even i thing the code above is correct,
why do i get the run time error.
Could you help again ?
BdLm
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10987829
maybe there's something in the ServerParameterForm.OnDestroy that causes the Exception....
0
 
LVL 8

Author Comment

by:BdLm
ID: 10987923
basically empty, i did not implement an OnDestroy procedure
 
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10988037
mmm...remove this part from TDClientFrame.EditBasicImageDataSet;

      If not Assigned(ServerParameterForm) then  
0
 
LVL 8

Author Comment

by:BdLm
ID: 10989799
i found 1 bug, with another more simple subform in my component:



type
  TMDIDataBaseForm = class(TForm)

    procedure Init(MyPointList :  TList);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    PointList       :  TList;

   

  end;

procedure TMDIDataBaseForm.FormCreate(Sender: TObject);
begin
      PointList:=TList.Create;
end;

procedure TMDIDataBaseForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
     //
end;

procedure TMDIDataBaseForm.FormDestroy(Sender: TObject);
begin
      PointList.Free;
      inherited;
end;




procedure TMDIDataBaseForm.Init(MyPointList : TList);
var  i                : Integer;
     APointRecord     : PPointList;
begin

    //*******************   Bug is here ---->>>>>>>>>>>>>>>>>>      
     PointList:= MyPointList;

end;


here must be some invalid operation, but i don't know why ?
May I not send a TList Object from my component to the sub-Form (lets call it child form)?
0
 
LVL 22

Expert Comment

by:Ferruccio Accalai
ID: 10994273
as i can see from the above posted you have to assign the pointlist instead to declare it :=

Just PointList.Assign(MyPointList);
0
 
LVL 8

Author Comment

by:BdLm
ID: 11049133
I'm still not happy with the data-exchange between the component and the "Child"-Form.
What you do for http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20985800.html
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
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: …

717 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