【问题标题】:Delphi not showing object/component "hints" when I am codding当我编码时,Delphi 没有显示对象/组件“提示”
【发布时间】:2013-05-07 00:40:24
【问题描述】:

如果我没记错的话,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.

【问题讨论】:

  • 组件名称下方是否有红色波浪线?在表格名称下怎么样?如果是这样,当您将鼠标悬停在它上面时,工具提示会告诉您什么?
  • 能否请附上表格的来源?
  • 或者至少只是 uses 子句...表单单元使用的所有单元。
  • TextoCompleto:= EditTexto.Text; 行将无法编译。您是否错过了之前的 procedure TForm1.ButtonGOClick(Sender: TObject); 之类的行?如果不是,请注意 EditTexto 是 TForm1 类型表单上的一个组件。它只能从 TForm1 类的方法中引用。例如ButtonGOClick,或使用实例变量或字段,例如默认的 Form1 变量 (Form1.EditTexto.Text)。如果没有缺少的行,您将在单元代码中添加等效的初始化部分。
  • 还要注意SL, Count and AppWin可能应该是局部变量。

标签: delphi delphi-7


【解决方案1】:

您将两种不同的 Delphi 单元样式混合为一种。您正在使用的单元是表单后面的单元 (.pas) 文件。但是,项目主文件 (.dpr) 具有不同的样式。

项目的主文件是唯一应该包含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.

一个新的 Delphi 标准单元文件看起来像这样:

unit Unit2;

interface

implementation

end.

一个新的 Delphi 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 表单应用程序。控制台应用程序主要基于命令提示符,这对于演示示例代码似乎很常见。但是,您不应该将该代码样式与任何其他标准单元样式混为一谈。

【讨论】:

  • 感谢 Jerry 提供了很好解释的解决方案。我不是程序员,10 年前就停止使用 delphi,甚至不记得程序的结构。现在我有点熟悉了,谢谢。
  • 请注意,在 pas 文件中使用 begin...end. 是允许的 - 它只是一种不带 finalization 子句的旧称 intialization 的方式。
  • 谢谢@GerryColl 我不知道。
【解决方案2】:

这称为代码完成。您可能无意中在选项中将其关闭。查看 Tools / Options / Editor Options / Code Insight,并确保选中 Code Completion。

【讨论】:

  • 它可能没有显示的原因有很多,例如在uses 子句中没有声明一个单位。
  • 如何检查一个单位是否没有在uses子句中声明?一件奇怪的事情是,当我提到一个组件时,它并没有找到它。示例:如果我使用 EditBox1.Text 它找不到,但如果我使用 Form1.EditBox1.Text 它可以工作。这是为什么呢?
【解决方案3】:

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

我怀疑您需要做的是在代码中的第一个 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.

【讨论】:

    【解决方案4】:

    所以其他人发现问题出在我的编码结构中,这是令人难以置信的错误。

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

    很容易看出,我已经开始在没有函数或过程的情况下进行编码。这就是为什么“提示”(实际上称为“代码洞察”,因为我也在其他人的帮助下发现)不起作用。 Delphi 没有将代码识别为任何事物的一部分,因此无法提供代码洞察力。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-29
      • 2022-11-19
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      相关资源
      最近更新 更多