在Delphi XE上,此代码对我不起作用:
http://delphi.about.com/cs/adptips2000/a/bltip0800_5.htm
procedure TForm1.FormDeactivate(Sender: TObject) ;
begin
ReleaseCapture;
end;
procedure TForm1.FormMouseMove
(Sender: TObject; Shift: TShiftState; X,Y: Integer) ;
begin
If GetCapture = 0 then
SetCapture(Form1.Handle) ;
if PtInRect(Rect(Form1.Left,
Form1.Top,
Form1.Left + Form1.Width,
Form1.Top + Form1.Height),
ClientToScreen(Point(x, y))) then
Form1.Caption := 'Mouse is over form' else
Form1.Caption := 'Mouse is outside of form';
end;
Run Code Online (Sandbox Code Playgroud)
没有错误 - 它只是没有效果.
请帮忙.
编辑1
事实证明问题不在于代码,即使鼠标FormMouseEnter和FormMouseLeave也不起作用,因为我将表单传递给我用这样的函数创建的单元:
程序Slide(Form:TForm; Show:Boolean);
我正在从这个过程中调用Show方法.我怎样才能克服这个问题?
谢谢.
编辑2
我不想使用我现在发布的功能.我想使用下面人们建议的内容(FormMouseEnter和FormMouseLeave),但它在我的情况下也不起作用.
在pascal中,我想随机选择1到50之间的循环数.每次选择一个数字时,该数字将被删除,直到最终在1到50之间没有数字可供选择并且循环结束.
如何在Pascal/Delphi中完成这样的事情?
我有"i"这是一个整数变量,我想做一个循环,将"i"从40000增加到90000,每次增加1000.每个结果都将出现在ComboBox中.
示例:40000 - 41000 - 42000 - 43000 - ... - 88000 - 89000 - 90000
我的代码如下:
var i:integer;
begin
for i:= 40000 to 90000 do
begin
ComboBox1.AddItem(IntToStr(i), nil); //until here the code works
Inc(i, 1000);
end;
Run Code Online (Sandbox Code Playgroud)
你有什么建议吗?
我目前面临的问题是无法将ClientWidth除以2(或乘以0.5,因为Delphi给出的错误信息:
[Error] Unit1.pas(59): Incompatible types: 'Integer' and 'Extended'
[Error] Unit1.pas(60): Incompatible types: 'Integer' and 'Extended'
[Error] Unit1.pas(61): Incompatible types: 'Integer' and 'Extended'
procedure TForm1.FormResize(Sender: TObject);
begin
// responsive design
with form1 do begin
cmdFakultat.left:=0.5*ClientWidth-60;
txtEingabe.left:=0.5*ClientWidth-60;
lblAusgabe.left:=0.5*ClientWidth-60;
end;
end;
end.
Run Code Online (Sandbox Code Playgroud) 我想将 TArray 中包含的所有值转换为 TDateTime 类型。ConvertDS 和 ConvertDE 是 TDateTime 变量,StoringData 是 TArray
StoringData : TArray<String>;
SetLength(StoringData,2);
for x := 0 to High(StoringData) do
for c := 0 to High(StoringData[x]) do
begin
StoringData[x] := TotTime;
StoringData[c] := DataCovertedS;
end;
ConvertDS := (StrToDateTime(StoringData[c]));
ConvertDE := (StrToDateTime(StoringData[c+1]));
Run Code Online (Sandbox Code Playgroud)
数据是这样分割的
Year := Copy(aData,0,4);
Month := Copy(aData,5,2);
Day := Copy(aData,7,2);
DataCovertedS := Concat(Year+'-'+Month+'-'+Day);
Run Code Online (Sandbox Code Playgroud)
当我尝试执行它时 StrToDateTime 不起作用。
根据正式的Pascal EBNF定义(pg69-75),我看到Pascal只支持3种原始类型:Integer,Real和String.
在C中,任何不同的值都0可以解释为true文字.Pascal不像C一样工作.当Pascal没有布尔类型时,它如何处理条件表达式?
我有以下代码,结果是42,但是为什么呢?答案必须是13,因为7+6=13。
program HelloWorld;
function F (a : integer) : integer;
begin
if (a = 1) or (a = 2) then
F := 2
else
F := F(a-1) + F(a-2);
end;
begin
WriteLn(F(8));
end.
Run Code Online (Sandbox Code Playgroud) 我认为我的问题有一个解决方案,但我找不到,你能帮助我吗?
我想做这样的事情:
var
a, b, c: string;
d: integer;
begin
a := StringGrid1.Cells[1,1];
b := StringGrid1.Cells[2,1];
c := StringGrid1.Cells[3,1];
d := StrToInt(a) + StrToInt(b) + StrToInt(c);
StringGrid1.Cells[4,1] := IntToStr(d);
end;
Run Code Online (Sandbox Code Playgroud)
但现在我需要声明200个字符串变量,就像在这个例子中一样.无论如何,这是一个"捷径"吗?
这是我试过的循环:
var
x: integer;
begin
for x := 1 to 200 do
begin
Form2.StringGrid1.Cells[3,209] := IntToStr(x);
end;
end;
Run Code Online (Sandbox Code Playgroud) 使用FastMM4时,函数DynArraySetLength中的system.pas存在内存泄漏.我正在使用一个列表,其中每个元素有5条记录.这些记录依次列出数百万的订单.因此,小内存泄漏积累为巨大的块.
在释放元素的同时,我故意使用SetLength(x,0)和x:= nil.但是,在system.pas的DynArraySetLength中仍然存在内存泄漏.有人可以建议我如何使用有效的方式释放阵列,并克服这个内存泄漏.
提前致谢
代码:此过程的SetLength发生内存泄漏
procedure TElem.Assign(Value: TElem);
begin
SetLength(Self.aXY.points, Length(Value.aXY.points)); //MEMORY LEAK
Move(Value.aXY.points[0], Self.aXY.points[0],
Length(Value.aXY.points) * SizeOf(coordinate));
end;
Run Code Online (Sandbox Code Playgroud)
在释放我正在使用此过程:
procedure TElem.FreeElem;
begin
SetLength(Self.aXY.points,0);
Self.aXY.points:=nil;
end;
Run Code Online (Sandbox Code Playgroud)