0

我正在尝试制作一个组合框,在更改后选择第一个项目。我的操作系统是 Ubuntu 12.04。我的代码:

unit Unit1; 

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  Buttons, Menus;

type

  { TForm1 }

  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Edit1: TEdit;
    Label1: TLabel;
    Memo1: TMemo;
    procedure ComboBox1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end; 

var
  Form1: TForm1; 

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.ComboBox1Change(Sender: TObject);
var Text2:String;
begin
  if (Combobox1.ItemIndex = 1) Then
  begin
    Text2 := Memo1.SelText;
    Edit1.Text := Memo1.SelText;
    Memo1.SelText := '[artist]' + Text2 + '[/artist]';
  end;
  if (Combobox1.ItemIndex = 2) Then
  begin
  if (Edit1.Text = '') Then
    ShowMessage('Artist name is not defined') Else
    begin
      Text2 := Memo1.SelText;
      Memo1.SelText := '[album artist=' + Edit1.Text + ']' + Text2 + '[/album]';
    end;
  end;
  if (ComboBox1.ItemIndex = 3) Then
  begin
  if (Edit1.Text = '') Then
    ShowMessage('Artist name is not defined') Else
    begin
      Text2 := Memo1.SelText;
      Memo1.SelText := '[track artist=' + Edit1.Text + ']' + Text2 + '[/track]'
    end;
  end;
  if (ComboBox1.ItemIndex = 4) Then
  begin
    Text2 := Memo1.SelText;
    Memo1.SelText := '[label]' + Text2 + '[/label]';
  end;
  if (ComboBox1.ItemIndex = 5) Then
  begin
    Text2 := Memo1.SelText;
    Memo1.SelText := '[tag]' + Text2 + '[/tag]';
  end;
  Combobox1.SelectFirst;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Text := 'Select an item';
end;

end.

这给出了一个错误:unit1.pas(74,13) 错误:标识符 idents 没有成员“SelectFirst”

我怎样才能解决这个问题?

4

1 回答 1

1

如果您希望第一项以这种方式选择它,则组合框没有此过程

ComboBox1.ItemIndex := 0
于 2014-02-24T20:11:09.320 回答