Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 349
  • Last Modified:

data exchange between component and a Form

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
BdLm
Asked:
BdLm
  • 9
  • 9
1 Solution
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
BdLmAuthor Commented:
still i get a run time error, i ' ll post more source code soon
0
 
BdLmAuthor Commented:
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
Independent Software Vendors: 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!

 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
BdLmAuthor Commented:
It works only once, recalling this code at a later step creates again an access vialoation
(writing to address .....)
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
BdLmAuthor Commented:
Ok, without ServerParameterForm.Free;
final Question:
If not Assigned(ServerParameterForm) then  
ServerParameterForm:=TServerParameterForm.create ??
0
 
BdLmAuthor Commented:
ServerParameterForm:=TServerParameterForm.create(nil) seems to be OK, but i should
exchange nil with the component , correct ?
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
@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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
BdLmAuthor Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
maybe there's something in the ServerParameterForm.OnDestroy that causes the Exception....
0
 
BdLmAuthor Commented:
basically empty, i did not implement an OnDestroy procedure
 
0
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
mmm...remove this part from TDClientFrame.EditBasicImageDataSet;

      If not Assigned(ServerParameterForm) then  
0
 
BdLmAuthor Commented:
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
 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
as i can see from the above posted you have to assign the pointlist instead to declare it :=

Just PointList.Assign(MyPointList);
0
 
BdLmAuthor Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 9
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now