FernandoSBS
FernandoSBS

Reputation: 655

Delphi not showing object/component "hints" when I am codding

If i'm not mistaken delphi has the ability to show a list of options after you insert a component name followed by the "." (dot) that precedes more arguments.

My delphi 7 is not showing this list after the "."

Ex: When I enter

form1.edit1.

It should show a list of options for an "TEdit" component. Not happening, what's wrong?

Code:

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.

Upvotes: 0

Views: 1694

Answers (4)

FernandoSBS
FernandoSBS

Reputation: 655

So as others have found out the problem was in my codding structure which was incredible wrong.

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

As easily seen I've started coding without a function or procedure. That's why the "hints" (actually called "Code Insights" as I've also found out with the help of others) were not working. Delphi was not recognizing the code as part of anything and so couldn't give code insights.

Upvotes: 0

Jerry Dodge
Jerry Dodge

Reputation: 27276

You have the two different Delphi unit styles mixed up into one. The unit which you're working with is the unit (.pas) file behind a form. However, a project main file (.dpr) has a different style.

The Project's main file is the only one which should include a begin..end. section. On the other hand, the rest of the units must have an implementation section where the actual code resides for multiple functions/procedures/methods etc.

So in your case, you need to keep your default form's unit in-tact how it was created by default.

A new Delphi main project file looks something like this:

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.

And a new Delphi standard unit file looks something like this:

unit Unit2;

interface

implementation

end.

And a new Delphi vcl form unit file looks something like this:

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.

And if you implement any code...

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.

One mistake you probably made was that the original code that you added to your form's unit was in the form of a sample console application, which is different from a VCL Forms Application. A Console Application is primarily based from a command prompt, which seems to be very common for demonstrating sample code. However, you should never mix up that code style with that of any other standard unit style.

Upvotes: 1

Gerry Coll
Gerry Coll

Reputation: 5975

I'm guessing a bit here, assuming that that code pasted above is unedited.

I suspect what you need to do is to add procedure TForm1.ButtonGOClick(Sender: TObject); before the first begin in your code:

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.

Upvotes: 0

Dale M
Dale M

Reputation: 843

It is called Code Completion. You may have inadvertently turned it off in your options. Look under Tools / Options / Editor Options / Code Insight, and ensure Code Completion is checked.

Upvotes: 1

Related Questions