A while ago I was pointed to a means by which I could get a list of Fonts & Printers available. This was via an 'Assign' to a TComboBox :
FontsAvailable: TComboBox;
procedure Read_Available_Fonts;
begin
Form1.FontsAvailable.Items.Assign(Screen.Fonts);
end;
Similarly for the Printer List.
This does the job perfectly but it demands that there is a TComboBox on the Form.
I would like to make the proc 'universal' by placing it in a Unit (which is added to the Uses Clause of the main Program) but of course this unit does not have a 'Form'.
I have attempted to add a TComboBox as a Var in the interface section of the unit
Var
FontList,
PrinterList : TComboBox;
... and create two procedures to get the data :
procedure Read_Available_Fonts;
begin
FontList.Items.Assign(Screen.Fonts);
end;
procedure Read_Printer_List;
begin
PrinterList.Items.Assign(Printer.Printers);
end;
This was accepted once I added
StdCtrls and
Printers to the Uses Clause and the program compiles.
However, at Runtime I get an 'External: ACCESS VIOLATION' when I call the Read_Printer_List. In debug mode I can continue and if I ignore a further warning I do get to see the main Form and from that I CAN see the list of Printers

but the call to read the Fonts (the next instruction) has not been done so there is obviously no Font list.
My next trial was to 'Create' the TComboBoxes :
PrinterList.Create(Nil);
FontList.Create(Nil);
. . . I initially tried (Self) as the argument but that wouldn't compile.
Now the ACCESS VIOLATION comes at
PrinterList.Create(Nil);Do I need to do more work as far as creating the TComboBoxes ? - The original versions (on the main form) have nothing changed in the Object Inspector - or is there something else that I'm simply missing?
[EDIT] - I've now tried using a TStringList rather than a TComboBox and the ACCESS VIOLATION comes at the end of
function TScreen.GetFonts : TStrings; In
Screen.inc