Delphi
--
Questions
--
Followers
Top Experts
What I would need is a correction to this code ot any code that would let me get a lit of all the tray name from a printer.
I kinow the error is exactly on the getmem, I think delphi XE have different ways to manage caracters strings.
Thank you for any help on this matter.
GetMem(p,24*DeviceCapabilities(pchar(PName),nil,DC_BINNAMES,nil,nil));
  for i:=1 to DeviceCapabilities(pchar(PName),nil,DC_BINNAMES,p,nil) do
  begin
    ComboName.items.add(p+24*(i-1));
  end;
  FreeMem(p);
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
http://www.efg2.com/Lab/Library/UseNet/1999/1102.txt
Here is the corrected code:
procedure TfMAin.GetPaperBins(sl: TStrings; PrinterName: String);
type
 TBinName = array [0..23] of Char;
 TBinNameArray = array [1..High(Integer) div SizeOf(TBinName)] of TBinName;
 PBinnameArray = ^TBinNameArray;
 TBinArray = array [1..High(Integer) div SizeOf(Word)] of Word;
 PBinArray = ^TBinArray;
var
 Device, Driver, Port: array [0..255] of Char;
 hDevMode: THandle;
 i, numBinNames, numBins, temp: Integer;
 pBinNames: PBinnameArray;
 pBins: PBinArray;
begin
 //set specified printer
 for numBins := 0 to Printer.Printers.Count -1 do begin
   if Printer.Printers [numBins] = PrinterName then
    Printer.PrinterIndex := numBins ;
 end;
 //original Code
  Printer.GetPrinter(Device,
 numBinNames := WinSpool.DeviceCapabilitie
 numBins   := WinSpool.DeviceCapabilitie
 if numBins <> numBinNames then
 begin
  raise Exception.Create('DeviceCa
 end;
 if numBinNames > 0 then
 begin
  pBins := nil;
  GetMem(pBinNames, numBinNames * SizeOf(TBinname));
  GetMem(pBins, numBins * SizeOf(Word));
  try
   WinSpool.DeviceCapabilitie
   WinSpool.DeviceCapabilitie
   sl.Clear;
   for i := 1 to numBinNames do
   begin
    temp := pBins^[i];
    sl.addObject(pBinNames^[i]
   end;
  finally
   FreeMem(pBinNames);
   if pBins <> nil then
    FreeMem(pBins);
  end;
 end;
end;






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Delphi
--
Questions
--
Followers
Top Experts
Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Developmentâ„¢. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.