我有这样的记录
TEmf_SrectchDIBits = packed record
rEMF_STRETCHDI_BITS: TEMRStretchDIBits;
rBitmapInfo: TBitmapInfo;
ImageSource: string;
end;
---
---
RecordData: TEmf_SrectchDIBits;
Run Code Online (Sandbox Code Playgroud)
如果我正在使用TStream将数据读入其中,则会发生异常
SetLength(RecordData.ImageSource, pRecordSize);
EMFStream.ReadBuffer(RecordData.ImageSource,pRecordSize)
Run Code Online (Sandbox Code Playgroud)
但如果我使用下面的代码,它正常工作
SetLength(RecordData.ImageSource, pRecordSize);
EMFStream.ReadBuffer(RecordData.ImageSource[1], pRecordSize);
Run Code Online (Sandbox Code Playgroud)
那么使用String和String有什么区别[1]
以下代码从Toolbar2000中复制.它是从INI文件中读取工具栏位置和停靠状态的例程的一部分.我在初始化期间称这个例程.下面的代码迭代主窗体上的所有组件(OwnerComponent)并加载它找到的任何工具栏的设置.
for I := 0 to OwnerComponent.ComponentCount-1 do begin
ToolWindow := OwnerComponent.Components[I]; // <------------------------
....
Run Code Online (Sandbox Code Playgroud)
这个迭代需要一些时间(秒 - 表单上有1500多个组件),我在显示的点上得到一个范围错误.我已经确定在执行此循环时正在从主窗体的组件中删除一个或多个项目,因此一旦发生这种情况,最终循环会尝试访问一个超过数组末尾的项目(可能最好将其编码为一个"downto"for循环来防止这种情况).
无论如何,我需要找出主要表单丢失组件的位置.谁能给我任何关于如何做到这一点的Delphi 2006调试技巧?我不希望在我的程序中释放任何主要表单组件.
UPDATE
我发现当我在设计时重新定位工具栏的默认停靠位置时,我无意中将它停靠在另一个工具栏上,而不是另一个工具栏所在的停靠站点.我通过从工具栏中删除工具栏来解决问题停靠并将其添加到码头.因此导致问题的安排是:
Dock
Toolbar 1
Control 1
Control 2
Toolbar 2
Control 3
Control 4
Run Code Online (Sandbox Code Playgroud)
并且解决方法是安排他们:
Dock
Toolbar 1
Control 1
Control 2
Toolbar 2
Control 3
Control 4
Run Code Online (Sandbox Code Playgroud)
它仍然指向TB2k代码中的一个错误 - 人们会认为它应该能够处理嵌套的工具栏.
我有一个 Delphi 2006 应用程序,它写入一个文件,然后定期将其重命名为有序名称,并创建一个新文件,即
open file.dat
write a record to file.dat
close file.dat
...
open file.dat
write a record to file.dat
close file.dat
rename file.dat to file20110818123456.dat
create file.dat
open file.dat
write a record to file.dat
close file.dat
...
Run Code Online (Sandbox Code Playgroud)
问题是有时重命名会失败并显示Error 32 - The process cannot access the file because it is being used by another process. 我正在检查重命名的目标是否不存在。就好像写入记录后文件的关闭不会立即发生。我在重命名过程中添加了一个循环来休眠一会儿,然后重试最多 10 次,但这没有帮助。
function RenameFileAtAllCosts (const OldFileID : TFilename ;
const NewFileID : TFilename ;
out ErrorCode : Integer) : boolean ; …Run Code Online (Sandbox Code Playgroud) 问题是:在提出异常之后,我可以阻止它从它自己的构造函数传播吗?考虑下面的代码:
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TMyErrorClass = class(Exception)
constructor Create(aMsg:String);
end;
TForm2 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
begin
//
raise TMyErrorClass.Create('test');
end;
{ TMyErrorClass}
constructor TMyErrorClass.Create(aMsg: String);
begin
{$IFDEF DEBUG}
Showmessage(aMsg);
{$ELSE}
//here I want to 'kill' the exception
{$ENDIF}
end;
end.
Run Code Online (Sandbox Code Playgroud)
在调用raise之后,如何在不添加try的情况下终止异常,而不是在我提出异常的地方?
LE:我有一个应用程序,它有近2000个这样的加注......而我正试图找到一个替代解决方案来为它编写错误处理....
继续该项目开始于:
如何根据其内容自动调整/缩放DBGrid(或其他类似的)列宽?
如何计算"左"属性以使文本在DBGrid单元格中居中?
当我们调用OnDrawColumnCell并使用Canvas编写文本来代替网格的默认绘制时,当我们想要将其置于单元格中心时,我们如何计算文本的位置?
我的D2006应用程序中有一个OnIdle处理程序.使用此代码:
procedure TMainForm.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
begin
Inc (IdleCalls) ;
Sleep (10) ;
Done := False ;
end ;
Run Code Online (Sandbox Code Playgroud)
应用程序运行平稳,空闲处理程序每秒调用100次,CPU使用率接近于零.
然后我添加了一个TActionList并将一些控件连接到操作,编写了一个Execute和Update处理程序.
procedure TMainForm.ActionNewButtonExecute(Sender: TObject);
begin
DoNewProject ;
end ;
procedure TMainForm.ActionNewButtonUpdate(Sender: TObject);
begin
ActionNewButton.Enabled := AccessLevelIsSupervisor ;
end;
Run Code Online (Sandbox Code Playgroud)
问题.OnUpdate事件不会触发.在预感中,我在OnIdle处理程序中设置了Done:= true,然后只有在我移动鼠标时才会调用OnIdle处理程序.并且更新操作仍然不会触发.
为什么更新处理程序可能不会被触发,我应该将Done设置为true还是false?或两者?
我有一个已经返回错误报告的应用程序.该应用程序是用Delphi 2006编写的,并在启动时挂起.MadExcept主线程堆栈如下所示.我怀疑没有默认打印机,但我不能在这里复制故障.

谁见过这个问题?
单元WWPrintToPrinterOrPDFRoutines的初始化部分
initialization
PagesRangeStartPage := 1 ;
PagesRangeEndPage := 999 ;
PrintRange := prAll ;
PrintCopies := 1 ;
PrintCollate := false ;
InitialPrintPaperName := 'A4' ;
if (Printer.Printers.Count = 0) then // <--------- this causes the hang
begin
InitialPrintOrientation := Printers.poPortrait ;
end
else
begin
InitialPrintOrientation := GetDefaultPrinterOrientation ;
InitialPrintPaperName := GetDefaultPrinterPaperName ;
end ;
CurrentPreviewPage := 1 ;
NDRMemoryStream := TMemoryStream.Create ;
Run Code Online (Sandbox Code Playgroud)
或拆解:
WWPrintToPrinterOrPDFRoutines.pas.682: PagesRangeStartPage := 1 ;
007C4404 C705EC8B81000100 mov [$00818bec],$00000001
WWPrintToPrinterOrPDFRoutines.pas.683: PagesRangeEndPage := 999 …Run Code Online (Sandbox Code Playgroud) 我有以下功能在Delphi 2006中工作,但在Delphi XE2下,它在处理时会产生访问冲突错误或特权指令错误RET.
function Q_TrimChar(const S: string; Ch: Char): string;
asm
PUSH ESI
MOV ESI,ECX
TEST EAX,EAX
JE @@qt
MOV ECX,[EAX-4]
TEST ECX,ECX
JE @@qt
PUSH EBX
PUSH EDI
MOV EBX,EAX
MOV EDI,EDX
XOR EDX,EDX
MOV EAX,ESI
CALL System.@LStrFromPCharLen
MOV EDX,EDI
MOV ECX,[EBX-4]
@@lp1: CMP DL,BYTE PTR [EBX]
JNE @@ex1
INC EBX
DEC ECX
JNE @@lp1
MOV EDX,[ESI]
JMP @@wq
@@ex1: DEC ECX
@@lp2: CMP DL,BYTE PTR [EBX+ECX]
JNE @@ex2
DEC ECX
JMP @@lp2
@@ex2: MOV EDI,[ESI]
LEA …Run Code Online (Sandbox Code Playgroud) 在我的问题: 如何使用"发件人"参数与"As"运算符一次超过一个类
我选择了Remy Lebeau的答案,因为它是大多数情况下最具活力的技术.它使用RTTI TypInfo类.
但是当我使用这个类时,另一个问题出现了: 我们如何设置子属性值?
function TRemote.UpdateQuery(DataSet: TDataSet; SQL: String): Boolean;
var
PropInfo: PPropInfo;
begin
{ atualiza o código SQL padrão de um dataSet de consulta tipo View }
PropInfo := GetPropInfo(DataSet, 'SQL', []);
if not Assigned(PropInfo) then
begin
Result := False;
Exit;
end;
try
DataSet.Close;
SetPropValue(DataSet, PropInfo, SQL);
DataSet.Open;
Result := True;
except
Result := False;
end;
end;
Run Code Online (Sandbox Code Playgroud)
示例:我有一个TIBQuery,我想更新SQL属性的文本.但是SQL属性是一个TStrings类,所以我必须使用SQL.Text.在上面的代码中,它将引发错误"无效的属性类型",因为我有一个TStrings,后来我尝试设置一个普通的字符串.
如何使用GetPropInfo访问SQL.Text? 是否有TIBQuery和TZQuery的共同祖先具有SQL属性,所以我可以更改为,而不是函数参数中的TDataSet?
我有一个没有组件的Delphi表单.然后,我创建了一个包含多个类的单元.我一直在尝试实例化类并在表单中创建一个对象,但它抱怨该类是未声明的.这是错误消息:'E2003 Undeclared Identifier:TUser'.
这是项目:
程序测试;
uses
Forms,
Home in 'Home.pas' {Form1},
uUser in 'uUser.pas';
{$R *.res}
begin
ReportMemoryLeaksOnShutdown := DebugHook <> 0;
Application.Initialize;
Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)
这是我的空表格:
unit Home;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uUser;
type
TForm1 = class(TForm)
private
{ Private declarations }
protected
public
{ Public declarations }
u : TUser; //It's complaining about TUser. I can right click on
TUser, and it will take me to the class declaration.
end;
var
Form1: …Run Code Online (Sandbox Code Playgroud) delphi ×10
delphi-2006 ×10
assembly ×1
basm ×1
components ×1
delphi-2007 ×1
delphi-xe2 ×1
file-rename ×1
hang ×1
printers ×1
python-idle ×1
rtti ×1
startup ×1
taction ×1
toolbar ×1