unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
ListView2: TListView;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Button3: TButton;
Edit3: TEdit;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure ListView2Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses StrUtils;
function AddSelItems(listview1:TListView;ListView2:TListView):Boolean;
var
s: string;
I,j: Integer;
begin
Result:=False;
if listview1.Selected =nil then exit;
for i := 0 to listview1.items.count - 1 do
begin
j:=ListView2.Items.Count;
if listview1.items[i].selected then
with ListView2.Items.Add do
begin
Caption:=IntToStr(j);
SubItems.add( listView1.Items[i].Caption );
SubItems.add(‘FileName2‘);
end;
end;
Result:=True;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ListView1.SelectAll;
AddSelItems(ListView1,ListVIew2);
end;
var
ID,FileName,NewName:string;
procedure TForm1.Button2Click(Sender: TObject);
var
i:Integer;
begin
for i:= 0 to ListView2.Items.Count -1 do
with ListView2 do
begin
ID:= Items[i].Caption;
FileName:=Items[i].SubItems.Strings[0] ;
Items[i].SubItems.Strings[1] := StringReplace(FileName,Edit1.Text,Edit2.Text,[rfReplaceAll]);
end;
end;
procedure TForm1.ListView2Click(Sender: TObject);
begin
if listview2.Selected =nil then exit;
with ListView2 do
begin
ID:= Items[ItemIndex].Caption;
FileName:=Items[ItemIndex].SubItems.Strings[0] ;
NewName:=Items[ItemIndex].SubItems.Strings[1] ;
end;
Form1.Caption:=Format(‘Id = %s FileName = %s Newname = %s‘,[ID,FileName,NewName]);
end;
procedure TForm1.FormShow(Sender: TObject);
begin
ListView1.SelectAll;
AddSelItems(ListView1,ListVIew2);
Button2.Click;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:Integer;
LStr,RStr:string;
begin
LStr:=LeftStr(Edit3.Text, Pos(‘*‘,Edit3.Text) -1 ) ;
RStr:=RightStr(Edit3.Text, Length(Edit3.text) - Pos(‘*‘,Edit3.Text) );
for i:= 0 to ListView2.Items.Count -1 do
with ListView2 do
begin
ID:= Items[i].Caption;
FileName:=Items[i].SubItems.Strings[0] ;
Items[i].SubItems.Strings[1] := Format(‘%s%s%s‘,[LStr,FileName,RStr]);
end;
end;
end.
来源: <">http://www.cnpack.org/>