关于StrDispose与Printer的问题 ( 积分: 50 )

  • 主题发起人 主题发起人 HongYuan
  • 开始时间 开始时间
H

HongYuan

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TPrintDBGridEh.SetPrintPager(VPrinter: TVirtualPrinter);
var
Device, Driver, Port: PChar;
HDMode: THandle;
PDMode: PDevMode;
PrintIni: TIniFile;//打印格式文件
begin

PrintIni :=TIniFile.Create(Trim(PrintIntFiles.Strings[0]));
with PrintInido
begin
TableFont.Name:=ReadString(Trim(PrintTableName.Strings[0]), 'TableFontName','宋体');
TableFont.Size:=ReadInteger(Trim(PrintTableName.Strings[0]), 'TableFontSize',9);
page.PageWidth:=ReadInteger(Trim(PrintTableName.Strings[0]), 'Width',2410);
page.PageHeight:=ReadInteger(Trim(PrintTableName.Strings[0]), 'Height',2800);
page.TopMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'TopMargin',2);
page.BottomMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'BottomMargin',2);
page.LeftMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'LeftMargin',2);
page.RightMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'RightMargin',2);
page.RowHeight:=ReadInteger(Trim(PrintTableName.Strings[0]), 'RowHeight',18);
page.Orientation:=ReadInteger(Trim(PrintTableName.Strings[0]), 'Orientation',0);
page.FitWidthToPage:=ReadBool(Trim(PrintTableName.Strings[0]), 'FitWidthToPage', True);
page.FitingType:=ReadInteger(Trim(PrintTableName.Strings[0]), 'FitingType',0);
end;
PrintIni.Free;
Device := StrAlloc(cchDeviceName);
Driver := StrAlloc(MAX_PATH);
Port := StrAlloc(32);
try
VPrinter.PrinterIndex := Printer.PrinterIndex;
VPrinter.GetPrinter(Device, Driver, Port, HDMode);
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode <> nil then
begin
with PDMode^do
begin
dmPaperSize := 256;
dmPaperWidth := Trunc(page.PageWidth);
dmPaperLength := Trunc(page.PageHeight);
dmFields := dmFields or DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
if Trunc(Page.Orientation)=0 then
dmOrientation := DMORIENT_PORTRAIT //纵向打印
else
dmOrientation := DMORIENT_LANDSCAPE;
//横向打印
GlobalUnlock(HDMode);
end;
VPrinter.PrinterIndex := Printer.PrinterIndex;
end;
end;
finally
StrDispose(Device);//这个在使用网络打印机时报地址错误或无效句柄,不知为何
StrDispose(Driver);
StrDispose(Port);
end;
end;
 
procedure TPrintDBGridEh.SetPrintPager(VPrinter: TVirtualPrinter);
var
Device, Driver, Port: PChar;
HDMode: THandle;
PDMode: PDevMode;
PrintIni: TIniFile;//打印格式文件
begin

PrintIni :=TIniFile.Create(Trim(PrintIntFiles.Strings[0]));
with PrintInido
begin
TableFont.Name:=ReadString(Trim(PrintTableName.Strings[0]), 'TableFontName','宋体');
TableFont.Size:=ReadInteger(Trim(PrintTableName.Strings[0]), 'TableFontSize',9);
page.PageWidth:=ReadInteger(Trim(PrintTableName.Strings[0]), 'Width',2410);
page.PageHeight:=ReadInteger(Trim(PrintTableName.Strings[0]), 'Height',2800);
page.TopMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'TopMargin',2);
page.BottomMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'BottomMargin',2);
page.LeftMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'LeftMargin',2);
page.RightMargin:=ReadInteger(Trim(PrintTableName.Strings[0]), 'RightMargin',2);
page.RowHeight:=ReadInteger(Trim(PrintTableName.Strings[0]), 'RowHeight',18);
page.Orientation:=ReadInteger(Trim(PrintTableName.Strings[0]), 'Orientation',0);
page.FitWidthToPage:=ReadBool(Trim(PrintTableName.Strings[0]), 'FitWidthToPage', True);
page.FitingType:=ReadInteger(Trim(PrintTableName.Strings[0]), 'FitingType',0);
end;
PrintIni.Free;
Device := StrAlloc(cchDeviceName);
Driver := StrAlloc(MAX_PATH);
Port := StrAlloc(32);
try
VPrinter.PrinterIndex := Printer.PrinterIndex;
VPrinter.GetPrinter(Device, Driver, Port, HDMode);
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode <> nil then
begin
with PDMode^do
begin
dmPaperSize := 256;
dmPaperWidth := Trunc(page.PageWidth);
dmPaperLength := Trunc(page.PageHeight);
dmFields := dmFields or DM_PAPERSIZE or DM_PAPERWIDTH or DM_PAPERLENGTH;
if Trunc(Page.Orientation)=0 then
dmOrientation := DMORIENT_PORTRAIT //纵向打印
else
dmOrientation := DMORIENT_LANDSCAPE;
//横向打印
GlobalUnlock(HDMode);
end;
VPrinter.PrinterIndex := Printer.PrinterIndex;
end;
end;
finally
StrDispose(Device);//这个在使用网络打印机时报地址错误或无效句柄,不知为何
StrDispose(Driver);
StrDispose(Port);
end;
end;
 
就是 StrDispose(Device);//这个在使用网络打印机时报地址错误或无效句柄,不知为何
出错,有没人有知道的?
 
cchDeviceName 怎么定义的?Device的长度够么?
 
接受答案了.
 
后退
顶部