Q&A

  • Unit1의 변수를 Unit2에서 어떻게 불러다가 쓰나요?
Unit1 의 변수를 Unit2에서 불러다 쓰고 싶습니다.

====================================================================
                                         Unit1
====================================================================
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, OleCtrls, SHDocVw, StdCtrls, ShellApi,Unit2,myUtil;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    GroupBox1: TGroupBox;
    RadioGroup1: TRadioGroup;
    RadioGroup2: TRadioGroup;
    RadioGroup3: TRadioGroup;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    ComboBox1: TComboBox;
    Button5: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
  PathName : string;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  path : string;
  serch_path : string;
implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  PathName := ExtractFilePath(Application.ExeName);
  WebBrowser1.Navigate(ExtractFilePath(Application.ExeName)+'./buyeo.html');
  combobox1.ItemIndex := 0;
  Edit1.Text := '';
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
    WebBrowser1.OleObject.Document.Body.Style.OverflowX := 'hidden';
    WebBrowser1.OleObject.Document.Body.Style.OverflowY := 'hidden';
end;

procedure TForm1.Button2Click(Sender: TObject);
var
    Search : String;
    SR : TSearchRec;
    GFile : TextFile;
    DataLine : String;
    Posion : Integer;
    FileName : string;
    num : Integer;
  begin

if Edit1.Text = '' then begin
        ShowMsg('검색어를 입력하세요.!', '텍스트검색', msgOk);

  end else begin
    num := 0;
    Search := Edit1.Text;
    Form2.ListBox1.Items.Clear;//검색창을 포메팅해준다
    if FindFirst(pathname + 'test_files*.*', faAnyFile, SR) = 0 then begin
        repeat
            if (SR.NAME <> '.') and (SR.NAME <> '..') then begin
            FileName := pathname + 'test_files' + Sr.Name;
            Assignfile(GFile,FileName);
            Reset(GFile);
            While not Eof(GFile) do begin
                ReadLn(GFile,DataLine);
                Posion := Pos(Search, UpperCase(DataLine));
                if Posion > 0 then begin
                    //num := num + 1 ;
                    Form2.ListBox1.Items.Add('"'+Search+'"포함 페이지'+ PChar(num) +' : '+ FileName {+ ' : ' + DataLine}); // <---- 여기있는 FileName변수를 Unit2에서 쓰고 싶습니다.

                end;
            end;
            CloseFile(GFile);
            end;

        until (FindNext(SR)<>0);

            if num < 1 then begin
               Form2.ListBox1.Items.Add('더이상 검색결과가 없습니다.');
            end;

        Form2.Show;
        Form2.Label2.Caption := Search;
        Edit1.Text := '';

    end;
    FindClose(SR);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if Edit2.Text = '' then begin
   ShowMsg('검색어를 입력하세요.!', '이미지검색', msgOk);
end else begin
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
if Edit3.Text = '' then begin
   ShowMsg('검색어를 입력하세요.!', '표검색', msgOk);
end else begin
end;

end;

procedure TForm1.Button5Click(Sender: TObject);
begin
Form2.Show;
end;

end.

====================================================================
                                         Unit2
====================================================================

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses Unit1,myutil;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
close;
end;



procedure TForm2.ListBox1DblClick(Sender: TObject);
var
  FileName : string;
begin
ShowMsg(Pchar(FileName), 'redirect_page', msgOk);
Form1.WebBrowser1.Navigate(Pchar(FileName)); //<---- 여기에 쓰고 싶습니다. 배열로 담았다가 써야 하나요?

end;

end.
11  COMMENTS