2013-05-07 83 views
0

如果我没有弄错,在插入组件名称后插入“。”,delphi有能力显示选项列表。 (点)在更多参数之前。当我编码时Delphi没有显示对象/组件“提示”

我的delphi 7在“。”之后没有显示这个列表。

例如:当我进入

form1.edit1. 

它应该显示的选项列表的“TEDIT”的组成部分。没有发生,怎么了?

代码:

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. 
+0

组件名称下方是否有红色的波浪线?在表单名称下怎么样?如果是这样,当你将鼠标悬停在它上面时,该工具提示告诉你什么? – 2013-05-07 00:42:42

+0

没事,没事。 – FernandoSBS 2013-05-07 01:23:19

+0

您能否包含您的表单来源? – 2013-05-07 01:41:12

回答

1

你有两种不同的德尔福单元风格混合成一个。您正在使用的单位是表单后面的单位(.pas)文件。但是,项目主文件()具有不同的风格。

该项目的主文件是唯一一个应包括begin..end.部分。另一方面,其余的单位必须有一个implementation部分,其中实际代码驻留多个功能/程序/方法等。

所以在你的情况下,你需要保持你的默认窗体的单位如何它是默认创建的。

一个新的Delphi 主项目文件看起来是这样的:

program Project1; 

uses 
    Vcl.Forms, 
    Unit1 in 'Unit1.pas' {Form1}; 

{$R *.res} 

begin 
    Application.Initialize; 
    Application.MainFormOnTaskbar := True; 
    Application.CreateForm(TForm1, Form1); 
    Application.Run; 
end. 

和新德尔福标准单元文件看起来是这样的:

unit Unit2; 

interface 

implementation 

end. 

和新德尔福vcl表单元文件看起来像这样:

unit Unit1; 

interface 

uses 
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs; 

type 
    TForm1 = class(TForm) 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

end. 

如果你执行任何代码...

unit Unit1; 

interface 

uses 
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs; 

type 
    TForm1 = class(TForm) 
    procedure FormCreate(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    procedure DoSomething; 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
    Form1.DoSomething; 
end; 

procedure TForm1.DoSomething; 
begin 
    //Do Something... 

end; 

end. 

一个错误,你可能做的是,您添加到您的窗体的单元原代码是一个示例控制台应用程序的形式,这是与VCL Forms Application不同。控制台应用程序主要基于命令提示符,这对于演示示例代码似乎非常常见。但是,您绝对不应该将该代码样式与任何其他标准单位样式混淆。

+0

感谢您解释得非常好的解决方案杰瑞。我不是程序员,并且在10年前停止与delphi合作,甚至不记得程序的结构。现在我有点更熟悉了,谢谢。 – FernandoSBS 2013-05-07 02:42:03

+1

请注意,在pas文件中使用'begin ... end.'是允许的 - 它只是一种较早的说法,并没有'finalization'子句的'intialization'。 – 2013-05-08 01:56:26

+0

谢谢@GerryColl我不知道。 – 2013-05-08 02:42:35

1

这就是所谓的代码完成。您可能无意中在选项中关闭了它。查看工具/选项/编辑器选项/代码洞察,并确保代码完成被选中。

+0

还有很多其他的原因,例如未在'uses'子句中声明的单元。 – 2013-05-07 01:07:41

+0

如何检查单元是否未在使用条款中声明?奇怪的是,当我提到一个组件时,它找不到它。例如:如果我使用EditBox1.Text它没有找到,但如果我使用Form1.EditBox1.Text它的作品。这是为什么? – FernandoSBS 2013-05-07 01:20:33

0

我在这里猜测,假设上面粘贴的代码是未经编辑的。

我怀疑你需要做的是在你的代码中的第begin之前添加procedure TForm1.ButtonGOClick(Sender: TObject);

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; 

implementation 

{$R *.dfm} 

procedure TForm1.ButtonGOClick(Sender: TObject); // <--- added line 
var 
    SL: TStringList;        // <-- moved variables from global to local scope. Form1 needs to remain global 
    Count: Integer; 
    Appwin : hWnd; 
    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. 
+0

是的,补充说明解决了它,后来我发现了它。 – FernandoSBS 2013-05-07 02:40:40

0

因此,其他人已经发现问题出在我的编码结构上,这是令人难以置信的错误。

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** 

正如我所看到的,我已经开始编写没有函数或过程的代码。这就是为什么“提示”(实际上称为“代码见解”,因为我也在其他人的帮助下发现了这些提示)不起作用。德尔福没有认识到代码是任何东西的一部分,所以无法提供代码见解。