Solved

data exchange between component and a Form

Posted on 2004-04-23
18
336 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

11 Experts available now in Live!

Get 1:1 Help Now