This is more a guess than an answer, because too much is not clear. Another thing is, I do answer it from a perspective of c++ Builder 6, because on a first glance (you mentioned
AnsiString
and also
Printer()->Printers
) it looks to be very similar.
Take into acount
Printer()->PrinterIndex
can be '-1' which means in Builder it is the default Printer. And in this case you can't get the printer name by
Printer()->Printers[p].GetText();
because this will end in index out of range or usually with borland in an access violation.
The next problem I face usually in Builder environement: In case no default printer is assigned (which is on the other hand very seldom under W10) you can get in problems.
Finally, accessing printer information needs to be done carefully. An example:
TStrings* prns= Printer()->Printers;
if (prns == NULL)
{
throw (*new Exception("Printer()->Printer returned NULL"));
}
LogDebugTxt("Available printers, no of printers is: " + AnsiString(prns->Count));
for (int ix= 0; ix < prns->Count; ix++)
{
LogDebugTxt(AnsiString(ix) + prns[ix]);
}
LogDebugTxt("Current Printer Index= " + AnsiString(Printer()->PrinterIndex));
I hope it helps and that I'm not completely wrong. Feel free to ask back.