delphi7中选中memo1中的某行,得到改行的内容
时间: 2023-06-25 08:02:22 浏览: 103
可以使用以下代码实现:
```
var
SelectedLine: Integer;
begin
// 获取当前选中行号
SelectedLine := Memo1.CaretPos.Y + 1;
// 获取当前选中行的内容
ShowMessage(Memo1.Lines[SelectedLine-1]);
end;
```
其中,`Memo1.CaretPos.Y` 获取当前光标所在行号(以0开始计数),加1后表示当前选中行号。`Memo1.Lines[SelectedLine-1]` 获取当前选中行的内容。你可以将这段代码放到事件处理程序中,比如一个按钮的`OnClick`事件中。
相关问题
delphi11 type 输出到memo 代码
下面是一个完整的 Delphi 11 示例程序,可以将类型信息输出到 Memo 控件:
```delphi
unit MainForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, TypInfo;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OutputTypeInfoToMemo(typ: PTypeInfo; memo: TMemo);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
OutputTypeInfoToMemo(TypeInfo(Integer), Memo1);
OutputTypeInfoToMemo(TypeInfo(string), Memo1);
OutputTypeInfoToMemo(TypeInfo(TColor), Memo1);
end;
procedure TForm1.OutputTypeInfoToMemo(typ: PTypeInfo; memo: TMemo);
var
s: string;
begin
s := GetTypeName(typ);
memo.Lines.Add(s);
end;
end.
```
在示例程序中,我们创建了一个名为 `TForm1` 的窗体,其中包含一个 `TMemo` 控件和一个按钮。单击按钮会将三种类型信息输出到 Memo 控件中。在 `OutputTypeInfoToMemo` 过程中,我们使用 `GetTypeName` 函数将类型信息转换为字符串,并将其附加到 Memo 控件的末尾。
delphi11 array 输出到memo 代码
下面是一个 Delphi 11 示例程序,可以将数组内容输出到 Memo 控件:
```delphi
unit MainForm;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure OutputArrayToMemo(arr: array of Integer; memo: TMemo);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
arr: array of Integer;
begin
SetLength(arr, 5);
arr[0] := 1;
arr[1] := 2;
arr[2] := 3;
arr[3] := 4;
arr[4] := 5;
OutputArrayToMemo(arr, Memo1);
end;
procedure TForm1.OutputArrayToMemo(arr: array of Integer; memo: TMemo);
var
i: Integer;
begin
for i := Low(arr) to High(arr) do
begin
memo.Lines.Add(IntToStr(arr[i]));
end;
end;
end.
```
在示例程序中,我们创建了一个名为 `TForm1` 的窗体,其中包含一个 `TMemo` 控件和一个按钮。单击按钮会创建一个整数数组,并将其传递给 `OutputArrayToMemo` 过程。在 `OutputArrayToMemo` 过程中,我们使用 `for` 循环遍历数组,并将每个元素转换为字符串并附加到 Memo 控件的末尾。