copyMemory(@Newarray[1],@MyArray[0],Len);
解决方案 »
- FormCreate和FormShow这两个事件有什么区别吗?
- 请教如何实现:当数据库改动,1个sever向多个client发出消息,向QQ那种方式弹出消息!
- 猜谜
- 我想請問一下: 有沒有哪個函數可以知道一個文本文檔一共有多少行?? 多謝了!!!
- Delphi调用VB写的exe程序,能不能象模态调用一个对话框一样,?也就是说主窗体此时什么也不能做,只有等这个exe关闭掉,才继续操作?
- ODAC 控件的帮助!
- access数据库加密后,如何再用ADO与之连接?
- 强烈征集:可以下载各种计算机图书的网址(delphi vc java ......)?100分
- delphi的简单问题
- 关于打印的问题.can you tell me????
- 三层结构大数据量传输问题
- 有本D5书写道:“要把ACTIVEX 控件的注册代码集成到应用程序中并不困难”,这句话什么意思??什么叫做注册代码??(DELPHI 5 开发人员指南 第155页)
copyMemory(@Myarray[1],@NewArray[1],Length(MyArray)-1);
Myarray[0]:=value;
用自定义的不对..
如:type
Taaa=Array[0..3] of Single;
Var
BB,TempBB:Array of Taaa;
aaa:Taaa;
setlength(TempBB,high(BB)+1);
aaa:=BB[0];
aaa[1]:=aaa[1]+1;//修改aaa其中的一个值
copyMemory(@TempBB[1],@BB[0],Length(BB)-1); //这里最后-1我用-length(BB[0])也不对
copyMemory(@BB[1],@TempBB[1],Length(BB)-1); //这里最后-1我用-length(BB[0])也不对
BB[0]:=aaa;请帮我调试一下吧
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
Taaa=Array[0..3] of Single; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
BB,TempBB:Array of Taaa;
aaa:Taaa;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
begin
setlength(BB,4);
setlength(TempBB,high(BB)+1);BB[0][0]:=0.1;
BB[0][1]:=0.2;
BB[0][2]:=0.3;
BB[0][3]:=0.4;
BB[1][0]:=1.1;
BB[1][1]:=1.2;
BB[1][2]:=1.3;
BB[1][3]:=1.4;
BB[2][0]:=2.1;
BB[2][1]:=2.2;
BB[2][2]:=2.3;
BB[2][3]:=2.4;
BB[3][0]:=3.1;
BB[3][1]:=3.2;
BB[3][2]:=3.3;
BB[3][3]:=3.4;
aaa:=BB[0];
aaa[1]:=aaa[1]+1;//修改aaa其中的一个值
copyMemory(@TempBB[1],@BB[0],Length(BB)-1); //这里最后-1我用-length(BB[0])也不对
copyMemory(@BB[1],@TempBB[1],Length(BB)-1); //这里最后-1我用-length(BB[0])也不对
BB[0]:=aaa;end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
Taaa=Array[0..3] of Single; TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
BB,TempBB:Array of Taaa;
aaa:Taaa;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
setlength(BB,4);
setlength(TempBB,high(BB)+1);BB[0][0]:=0.1;
BB[0][1]:=0.2;
BB[0][2]:=0.3;
BB[0][3]:=0.4;BB[1][0]:=1.1;
BB[1][1]:=1.2;
BB[1][2]:=1.3;
BB[1][3]:=1.4;BB[2][0]:=2.1;
BB[2][1]:=2.2;
BB[2][2]:=2.3;
BB[2][3]:=2.4;BB[3][0]:=3.1;
BB[3][1]:=3.2;
BB[3][2]:=3.3;
BB[3][3]:=3.4;Listbox1.Items.Add('BB[i][0]:');
for i:=0 to high(BB) do
begin
listbox1.Items.Add(floattostr(BB[i][0]));
end;Listbox1.Items.Add('BB[i][1]:');
for i:=0 to high(BB) do
begin
listbox1.Items.Add(floattostr(BB[i][1]));
end;Listbox1.Items.Add('BB[i][2]:');
for i:=0 to high(BB) do
begin
listbox1.Items.Add(floattostr(BB[i][2]));
end;
aaa:=BB[0];
aaa[1]:=aaa[1]+1;
copyMemory(@TempBB[1],@BB[0],Length(BB)-1);
copyMemory(@BB[1],@TempBB[1],Length(BB)-1);
BB[0]:=aaa;Listbox2.Items.Add('BB[i][0]:');
for i:=0 to high(BB) do
begin
listbox2.Items.Add(floattostr(BB[i][0]));
end;Listbox2.Items.Add('BB[i][1]:');
for i:=0 to high(BB) do
begin
listbox2.Items.Add(floattostr(BB[i][1]));
end;Listbox2.Items.Add('BB[i][2]:');
for i:=0 to high(BB) do
begin
listbox2.Items.Add(floattostr(BB[i][2]));
end;
end;end.
第一个参数是目标地址
第二个参数是源地址
第一个参数是拷贝长度(Byte)
airwing说的不对,应该用
copyMemory(@Newarray[1],@MyArray[0],(Length(MyArray)-1)*sizeof(single));
才对
应该是copyMemory(@Newarray[1],@MyArray[0],sizeif(MyArray));
这回是对的了,jera!太久没用了,都忘了length是数组长度了
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
Taaa=Array[0..3] of Single; TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
BB,TempBB:Array of Taaa;
aaa:Taaa;
implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
setlength(BB,4);
setlength(TempBB,high(BB)+1);BB[0][0]:=0.1;
BB[0][1]:=0.2;
BB[0][2]:=0.3;
BB[0][3]:=0.4;BB[1][0]:=1.1;
BB[1][1]:=1.2;
BB[1][2]:=1.3;
BB[1][3]:=1.4;BB[2][0]:=2.1;
BB[2][1]:=2.2;
BB[2][2]:=2.3;
BB[2][3]:=2.4;BB[3][0]:=3.1;
BB[3][1]:=3.2;
BB[3][2]:=3.3;
BB[3][3]:=3.4;Listbox1.Items.Add('BB[i][0]:');
for i:=0 to high(BB) do
begin
listbox1.Items.Add(floattostr(BB[i][0]));
end;Listbox1.Items.Add('BB[i][1]:');
for i:=0 to high(BB) do
begin
listbox1.Items.Add(floattostr(BB[i][1]));
end;Listbox1.Items.Add('BB[i][2]:');
for i:=0 to high(BB) do
begin
listbox1.Items.Add(floattostr(BB[i][2]));
end;
aaa:=BB[0];
aaa[1]:=aaa[1]+1;
copyMemory(@TempBB[1],@BB[0],(Length(BB)-1)*sizeof(single));
copyMemory(@BB[1],@TempBB[1],(Length(BB)-1)*sizeof(single));
BB[0]:=aaa;Listbox2.Items.Add('BB[i][0]:');
for i:=0 to high(BB) do
begin
listbox2.Items.Add(floattostr(BB[i][0]));
end;Listbox2.Items.Add('BB[i][1]:');
for i:=0 to high(BB) do
begin
listbox2.Items.Add(floattostr(BB[i][1]));
end;Listbox2.Items.Add('BB[i][2]:');
for i:=0 to high(BB) do
begin
listbox2.Items.Add(floattostr(BB[i][2]));
end;
end;end.
aaa[1]:=aaa[1]+1;
copyMemory(@TempBB[1],@BB[0],Length(BB)-sizeof(BB[0]));
copyMemory(@BB[1],@TempBB[1],Length(BB)-sizeof(BB[0]));
BB[0]:=aaa;
aaa[1]:=aaa[1]+1;
copyMemory(@TempBB[1],@BB[0],sizeof(BB));
copyMemory(@BB[1],@TempBB[1],sizeof(BB));
BB[0]:=aaa;
Taaa=Array[0..3] of Single;
Var
BB,TempBB:Array of Taaa;
aaa:Taaa;//BB是动态数组在其他过程里已经Setlength并赋了值
setlength(TempBB,high(BB)+1);
aaa:=BB[0];
aaa[1]:=aaa[1]+1;//修改aaa其中的一个值
copyMemory(@TempBB[1],@BB[0],sizeof(BB));
copyMemory(@BB[1],@TempBB[1],sizeof(BB));
BB[0]:=aaa;
//用Copy()就可以了procedure TForm1.Button1Click(Sender: TObject);
const
cCount = 10;
type
TArrayType = Single;
TArray = array of TArrayType;
var
vArray: TArray;
I: Integer;
function ArrayToStr(mArray: TArray): string;
var
I: Integer;
begin
Result := '';
for I := Low(mArray) to High(mArray) do
AppendStr(Result, Format('a[%d]=%s', [I, VarToStr(mArray[I])]) + #13#10);
end;
begin
SetLength(vArray, cCount);
for I := 0 to Pred(cCount) do vArray[I] := I;
ShowMessage(ArrayToStr(vArray));
vArray := Copy(vArray, 1, 9);
SetLength(vArray, cCount);
vArray[Pred(cCount)] := 0;
ShowMessage(ArrayToStr(vArray));
vArray := nil;
end;
但是当数组长度很长时,速度会慢
aaa:array[0..3] of single ;copymemory(@aaa[0],@BB[0],sizeof(bb[0]));
aaa[1]:=aaa[1]+1;
copyMemory(@TempBB[1],@BB[0],sizeof(bb[0])*Length(BB));
copyMemory(@BB[1],@TempBB[1],sizeof(bb[0])*Length(BB));
copymemory(@bb[0],@aaa[0],sizeof(bb[0]));
我解决了 应该是这样
BB,TempBB:Array of array[0..3] of single ;
aaa:array[0..3] of single ;copymemory(@aaa[0],@BB[0],sizeof(bb[0]));
aaa[1]:=aaa[1]+1;
copyMemory(@TempBB[1],@BB[0],sizeof(bb[0])*(Length(BB)-1));
copyMemory(@BB[1],@TempBB[1],sizeof(bb[0])*(Length(BB)-1));
copymemory(@bb[0],@aaa[0],sizeof(bb[0]));