Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

problem with exchanging data between 2 forms

Posted on 1999-01-24
2
Medium Priority
?
267 Views
Last Modified: 2010-04-06

Hi experts,

I have a problem if I want to exchange data between 2 forms.

My application consits of 2 forms:

form1:
------

drivelistbox,directorylistbox,filelistbox, filterlistbox
commandbutton


form2:
------

3 editboxes, 1 commandbutton


If I press the button of form1, I read the selected name of the selected textfile to a string variable.

Now I open the file and want to copy the lines within the textfile to the editboxes of form2.
And this copying is not so easy for me.

I can't assign this copying to the button of form1, because in form1 the editboxes of form2 are unknown.
And if I assign this copying to the comandbutton of form2, the editboxes are known, but now the selected
filename will be an unknown identifier for Delphi.

I have one idea in my mind.

In form1 I could try something like

form2.edit1.text:'bla bla bla';

BUT; I want to manipulate the editboxes of form2 with the help of this routines:

function SplitStrAt(var s: string; position: Integer): string;
var
  i, mark: Integer;
begin
  mark := 0;

  for i := 1 to Length(s) do begin
    if (s[i] in delimiters) or (i = length(s)) then mark := i;
    if (i >= position) or (i = Length(s)) then begin
      Result := Copy(s, 1, mark);
      Delete(s, 1, Mark);
      break;
    end;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
  i: integer;
begin
  s := 'This is a sample string which should be examined by the experts' +
    'in order to demonstrate which result I want if I split a string.';
  while s <> '' do
    for i := 0 to ComponentCount - 1 do
      if (Components[i] is TEdit) then
        TEdit(Components[i]).Text := SplitStrAt(s, 50);
end;

But the code of

procedure TForm1.Button1Click(Sender: TObject);

works only if both file selection and string manipulation are done within only one form.
As the form with the editboxes is already filled with other stuff, I have to avoid this
overloading and Imust use 2different forms.

Have you an idea, how my problem could be solved ?





0
Comment
Question by:mathes
[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
2 Comments
 
LVL 1

Accepted Solution

by:
martin_g earned 80 total points
ID: 1363127
The first simple thing that you'll wnat to check is the "uses" section of your forms.  On the Form1 unit in the "uses" clause just below interface, place a reference to the unit containing your Form2. Now in the Form2 unit, place a uses clause  immediately below the implementation clause referring back to your form 1 unit.

Having donw this both units should reconize each other.  Than to exchange data you simply do this:

Form2.edit1.text := Form1.edit1.text;

Or in your Button1Click
procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
  i: integer;
begin
  s := 'This is a sample string which should be examined by the experts' +
    'in order to demonstrate which result I want if I split a string.';
  while s <> '' do
    for i := 0 to Form2.ComponentCount - 1 do
      if (Form2.Components[i] is TEdit) then
        TEdit(Form2.Components[i]).Text := SplitStrAt(s, 50);
end;

Hope this helps!
Martin Gauss

0
 

Author Comment

by:mathes
ID: 1363128
Hi expert,

thank you for your help.

This is exactly what I was looking for.


With kind regards

Mathes

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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