-3

由于 EditTexto 是 form1 的对象(我正在处理),为什么我尝试时无法识别它:

Texto:= EditTexto.Text;

???

如果我使用 Form1.EditTexto.Text 它似乎接受它。

4

1 回答 1

1

文本代码不在表单对象的范围内。刚进单位。我相信这就是问题所在。在我将文本移动到按钮的“onclick”事件后,它开始识别 editTexto 对象。这有意义吗?

前:

    unit Banri;

interface

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

type
  TForm1 = class(TForm)
    EditTexto: TEdit;
    ButtonGO: TButton;
    procedure ButtonGOClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  SL: TStringList;
  Count: Integer;
  Appwin : hWnd;

implementation

{$R *.dfm}

  var
  TextoCompleto: String;


begin
  TextoCompleto:= EditTexto.Text;
  Appwin:= FindWindow(PChar(0),'Banrisul');
  if Appwin <> 0 then
  begin
      StringReplace(TextoCompleto, '.', '', [rfReplaceAll, rfIgnoreCase]);

      SL:= TStringList.Create;
      try
        ExtractStrings([' '], [], PChar(TextoCompleto), SL);
        WriteLn(SL.Text);
        ReadLn;
      finally
        SL.Free;
  end;
      Count:= 0;
      while Count <> SL.Count - 1 do
        begin
          Clipboard.AsText:= SL[Count];; //place text in clipboard
          //if Clipboard.HasFormat(CF_TEXT) then
          //do something with text
          ShowMessage(Clipboard.AsText);
          Clipboard.AsText:= SL[Count + 1];; //place next line text in clipboard
          //if Clipboard.HasFormat(CF_TEXT) then
          //do something with text
          inc(Count);
        end; //while Count <> SL.Count - 1 do
      SL.Free;
  end; //if Appwin <> 0 then

end.

后:

unit Banri;

interface

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

type
  TForm1 = class(TForm)
    EditTexto: TEdit;
    ButtonGO: TButton;
    procedure ButtonGOClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  SL: TStringList;
  Count: Integer;
  Appwin : hWnd;

implementation

{$R *.dfm}

  var
  TextoCompleto: String;


procedure TForm1.ButtonGOClick(Sender: TObject);
begin
  TextoCompleto:= EditTexto.Text;
  Appwin:= FindWindow(PChar(0),'Banrisul');
  if Appwin <> 0 then
  begin
      StringReplace(TextoCompleto, '.', '', [rfReplaceAll, rfIgnoreCase]);

      SL:= TStringList.Create;
      try
        ExtractStrings([' '], [], PChar(TextoCompleto), SL);
        WriteLn(SL.Text);
        ReadLn;
      finally
        SL.Free;
  end;
      Count:= 0;
      while Count <> SL.Count - 1 do
        begin
          Clipboard.AsText:= SL[Count];; //place text in clipboard
          //if Clipboard.HasFormat(CF_TEXT) then
          //do something with text
          ShowMessage(Clipboard.AsText);
          Clipboard.AsText:= SL[Count + 1];; //place next line text in clipboard
          //if Clipboard.HasFormat(CF_TEXT) then
          //do something with text
          inc(Count);
        end; //while Count <> SL.Count - 1 do
      SL.Free;
  end; //if Appwin <> 0 then
end;

end.
于 2013-05-07T01:53:00.193 回答