Solved

data exchange between component and a Form

Posted on 2004-04-23
18
337 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
  • 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
 
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
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 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

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
Thread safe  opinion 7 126
error 1.1 400 Bad request idhttp delphi 18 55
CheckListBox usage 3 51
Delphi Ado Query To Converts Joined Columns Into Rows Based on Primary Key 4 39
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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

13 Experts available now in Live!

Get 1:1 Help Now