Recent

Author Topic: "Charles Petzold" Style Programming Book or Document?  (Read 5612 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #15 on: September 27, 2020, 09:36:05 pm »
An example program is available with FPC install in demo/win32/edit.pp

"Tomes of Delphi Win32" api and win32 graphics api might also be good books

pmckone

  • Newbie
  • Posts: 5
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #16 on: September 28, 2020, 12:34:39 am »
I didn't make the original question clear enough.  I actually already know how to write old-fashioned Win32 programs in C.  I wrote Algol at Burroughs around 1980, and Pascal on a Convergent Technologies machine in 1982, and converting 'C' code to Pascal isn't too hard.  What I'm hoping to find is an explanation of how to use the component libraries, but without using a form designer.  Many years ago I found a book "Introduction to MFC Programming with Visual C++" written by Richard M. Jones.  He explains how to write what he calls "Handcrafted MFC Programs".  I was hoping to find a similar book about writing Delphi programs by hand.  It's beginning to look like no such book exists.  That's okay.  It wouldn't be the first time I tried to find something that doesn't exist!
« Last Edit: September 28, 2020, 12:36:29 am by pmckone »

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #17 on: September 28, 2020, 08:51:28 am »
I for one understand perfectly well what you're saying. And I'd point out that when LBS transitioned from using a Medium System to a B7800 circa 1981 they hired about 25 coders to design TD830J and Modular Terminal screens for them... work that these days is almost entirely automated.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #18 on: September 28, 2020, 09:30:59 am »
Many years ago I found a book "Introduction to MFC Programming with Visual C++" written by Richard M. Jones.  He explains how to write what he calls "Handcrafted MFC Programs".  I was hoping to find a similar book about writing Delphi programs by hand.  It's beginning to look like no such book exists.  That's okay.  It wouldn't be the first time I tried to find something that doesn't exist!

I don't think there is a book, but it is quite common to do at least parts (like whole forms) by hand. The designer operates on textfiles (lfm/dfm and .pas/pp), and just watching what changes it makes is often enough.

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #19 on: September 29, 2020, 01:57:45 am »
Well HTML, JavaScript and CSS are all by hand, there are editors but you can not use them if you like  :P

So what's the point =)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #20 on: September 29, 2020, 09:02:22 am »
Well HTML, JavaScript and CSS are all by hand, there are editors but you can not use them if you like  :P

Which is why I mentioned Borland Intranet Builder (?) and Netscape Visual Javascript in my list earlier. The distinguishing feature is that they know how to hook Javascript onto DOM events, even if they don't provide as much coding and debugging support as Delphi etc.

The fact that an influential group of people refuses to use available tools doesn't make their refusal praiseworthy.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #21 on: September 29, 2020, 11:20:46 am »
Topic: "Charles Petzold" Style Programming Book or Document?

Can I get a recommendation for a book or document that explains how to write programs that use the component libraries WITHOUT using a form designer?  Every book that I look at starts out with dragging and dropping controls onto a form, and then augmenting code that is generated by a form designer.  I'm more comfortable writing all the code myself.  Thanks.
Just curiosity.
Which books specifically are you referring to?
http://www.computerofthetides.com/bio.html
https://en.wikipedia.org/wiki/Charles_Petzold
https://www.charlespetzold.com/
https://www.amazon.com/Charles-Petzold/e/B000APETXO%3Fref=dbs_a_mng_rwt_scns_share
https://www.amazon.com/Books-Charles-Petzold/s?rh=n%3A283155%2Cp_27%3ACharles+Petzold

valdir.marcos

  • Hero Member
  • *****
  • Posts: 1106
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #22 on: September 29, 2020, 12:44:08 pm »
I didn't make the original question clear enough.  I actually already know how to write old-fashioned Win32 programs in C.  I wrote Algol at Burroughs around 1980, and Pascal on a Convergent Technologies machine in 1982, and converting 'C' code to Pascal isn't too hard.  What I'm hoping to find is an explanation of how to use the component libraries, but without using a form designer.  Many years ago I found a book "Introduction to MFC Programming with Visual C++" written by Richard M. Jones.  He explains how to write what he calls "Handcrafted MFC Programs".  I was hoping to find a similar book about writing Delphi programs by hand.  It's beginning to look like no such book exists.  That's okay.  It wouldn't be the first time I tried to find something that doesn't exist!
Like marcov said, I also don't think there is such a book, but the internet is full of Delphi examples that would work on Lazarus:
https://stackoverflow.com/questions/16112924/how-to-create-a-form-programmatically-with-a-couple-components-on-it-in-delphi
https://stackoverflow.com/questions/43450671/how-to-create-a-new-form-dynamically-and-inherit-the-form-from-an-existing-form
http://www.festra.com/wwwboard/messages/12948.html


Introduction to MFC Programming with Visual C++,  Richard M. Jones, 2000:
https://catalyst.library.jhu.edu/catalog/bib_2150987
https://archive.org/details/introductiontomf00rich/page/n5/mode/2up

pmckone

  • Newbie
  • Posts: 5
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #23 on: September 29, 2020, 06:52:16 pm »
The Petzold books that I own are "Programming Windows" (versions for 3.0, 95, and 98), "Programming Windows with C#" and the update "Programming Windows Forms" and "Applications = Code + Markup", which is about Windows Presentation Foundation.  I stopped reading this last book when I realized the the "SpinBox" control was not included in WPF.  I don't think Petzold used a form designer (Or "AppWizard") to produce any of examples in any of these books except possibly the last one, which I didn't finish. 

In my case, I am constructing a chessboard using an 8x8 array of Rich Text boxes, all sharing the same event handler.  I have already written this program in C#, but now I need it in Pascal, to merge with the old Turbo Games chess program.  I think it would take me longer to learn how create a two-dimensional array of text boxes in the form designer than it will take to write the code directly.  Why am I using Rich Text boxes to make the squares on the board?  Because is reduces the amount of keyboard handling code that I have to write.

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #24 on: September 29, 2020, 07:41:37 pm »
What I'm hoping to find is an explanation of how to use the component libraries, but without using a form designer.

I wonder why you avoid using form designer. It is easy to learn and you can develop programs in much less time.

You mentioned you're writing games, glad to meet someone who likes writing games here. Maybe you're interested to learn writing a simple snake game I wrote some time ago:
https://forum.lazarus.freepascal.org/index.php/topic,38136.msg258381.html#msg258381

There you can learn reading user input, using TTimer as a game loop, using buffer for better keyboard input, how to reduce flickering, and many basic things for writing games. As you're already able to write games in C#, I'm sure you already knew about them but you might be don't know how to do them in Pascal. Unfortunately that thread is very long and messy.

If you're new in Pascal/Lazarus, I recommend you this page:
https://wiki.freepascal.org/Portal:HowTo_Demos

You can find many short demos especially in the 'Graphics' and 'User Interface' categories, which can help you learn GUI programming easier.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #25 on: September 29, 2020, 08:39:18 pm »
I don't think Petzold used a form designer (Or "AppWizard") to produce any of examples in any of these books except possibly the last one, which I didn't finish.

For exactly the same reason that cavemen didn't use matches to light their fire: such things did not exist.

Petzold's reputation was founded on his work with DOS and Windows 3.x To a very large extent hos subsequent books hewed carefully to the same format, with the intention that they helped his existing clientele adapt to the new technology. He left other people to write about development tools.

Quote
In my case, I am constructing a chessboard using an 8x8 array of Rich Text boxes, all sharing the same event handler.  I have already written this program in C#, but now I need it in Pascal, to merge with the old Turbo Games chess program.  I think it would take me longer to learn how create a two-dimensional array of text boxes in the form designer than it will take to write the code directly.  Why am I using Rich Text boxes to make the squares on the board?  Because is reduces the amount of keyboard handling code that I have to write.

Get a form, slap an 8x8 array of panels onto it. Or use a TDrawGrid. Or just about anything. Because the work you make for yourself and the grief you cause the community insisting on doing everything by hand will far exceed the work and grief associated with helping you out with keyboard handling.

MarkMLl

(Who's BT, DT, spent far too much time reinventing the wheel and bashing his head against tools when he's tried to abuse them, and wishes that less experienced users would just now and then /listen/ to what people were trying to tell them.)
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #26 on: January 17, 2021, 03:00:35 am »
What I'm hoping to find is an explanation of how to use the component libraries, but without using a form designer.

Everything that can be done via the Lazarus form designer can be done in code as well.

Some references:
https://wiki.freepascal.org/Form_Tutorial#Creating_a_new_form_dynamically
https://forum.lazarus.freepascal.org/index.php?topic=37530.0

When designing a form visually, units are automatically added to the uses declaration, fields and methods are automatically add to a TForm class and properties are stored in a corresponding .lfm file.  The .lfm file is linked into the program as a resource (via the line {$R *.lfm}).  An .lfm file looks like this:
Code: Pascal  [Select][+][-]
  1. object Form1: TForm1
  2.   Left = 599
  3.   Height = 172
  4.   Top = 495
  5.   Width = 180
  6.   Caption = 'Form1'
  7.   ClientHeight = 172
  8.   ClientWidth = 180
  9.   LCLVersion = '2.0.8.0'
  10.   object Button1: TButton
  11.     Left = 32
  12.     Height = 25
  13.     Top = 64
  14.     Width = 75
  15.     Caption = 'Button1'
  16.     TabOrder = 0
  17.   end
  18.   object Label1: TLabel
  19.     Left = 40
  20.     Height = 17
  21.     Top = 40
  22.     Width = 37
  23.     Caption = 'Label1'
  24.     ParentColor = False
  25.   end
  26. end
  27.  

To create the form and components in code, and without using an .lfm file, a project1.lpr file (originally generated by Lazarus) can be modified like this:
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Interfaces, // this includes the LCL widgetset
  10.   Forms, Unit1
  11.   { you can add units after this };
  12.  
  13. //{$R *.res}  //we don't need this since we are creating the form and associated controls in code
  14.  
  15. begin
  16.   RequireDerivedFormResource:=False;  //changed this to false since we are not linking/loading an .lfm resource
  17.   Application.Scaled:=True;
  18.   Application.Initialize;
  19.   unit1.CreateAndShowMyMainForm;  //this calls our code to create and show the main form
  20. //  Application.CreateForm(TForm1, Form1);  //we don't need this, since we are creating the form and setting the properties in code
  21.   Application.Run;
  22. end.
  23.  

unit1.pas which creates the form might look like this:
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     Label1: TLabel;
  17.     procedure Button1Click(Sender: TObject);
  18.   end;
  19.  
  20. procedure CreateAndShowMyMainForm;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. //{$R *.lfm}  //we don't need this since we are creating the form in code
  28.  
  29. procedure CreateAndShowMyMainForm;
  30. begin
  31.   Form1 := TForm1.Create(Application);  //In this example, Application is the "owner" of the control and will free it for us
  32.   with Form1 do begin
  33.     Left := 603;
  34.     Height := 172;
  35.     Top := 168;
  36.     Width := 180;
  37.     Caption := 'Form1';
  38.     ClientHeight := 172;
  39.     ClientWidth := 180;
  40.   end;
  41.  
  42.   Form1.Button1 := TButton.Create(Form1);
  43.   with Form1.Button1 do begin
  44.     Left := 32;
  45.     Height := 25;
  46.     Top := 64;
  47.     Width := 75;
  48.     Caption := 'Button1';
  49.     OnClick := @Form1.Button1Click;
  50.     TabOrder := 0;
  51.     Parent := Form1;
  52.   end;
  53.  
  54.   Form1.Label1 := TLabel.Create(Form1);
  55.   with Form1.Label1 do begin
  56.     Left := 40;
  57.     Height := 17;
  58.     Top := 40;
  59.     Width := 37;
  60.     Caption := 'Label1';
  61.     ParentColor := False;
  62.     Parent := Form1;
  63.   end;
  64.  
  65.   Form1.Show;
  66. end;
  67.  
  68. { TForm1 }
  69.  
  70. procedure TForm1.Button1Click(Sender: TObject);
  71. begin
  72.   Label1.Caption := 'Hello World';
  73. end;
  74.  
  75. end.
  76.  

And if you want to control the freeing of your form, then don't give it an owner when you create it:
  Form1 := TForm1.Create(nil);

As a side point, the Delphi gexperts "Components to Code" IDE expert converts gui components to pascal code:
http://www.gexperts.org/tour/index.html?components_to_code.html
(I don't know of a Lazarus implementation of "Components to Code", but it would not be hard to port the one from gexperts)
« Last Edit: January 17, 2021, 03:41:07 am by WayneSherman »

Blade

  • Full Member
  • ***
  • Posts: 177
Re: "Charles Petzold" Style Programming Book or Document?
« Reply #27 on: January 18, 2021, 03:00:28 am »
Everything that can be done via the Lazarus form designer can be done in code as well.

That was a well done example.  Also, I think some people (maybe pmckone also) like dynamic alternatives because .lfm data shows up in tools like Resource Hacker.  So if for nothing else, dynamically generated forms can provide some additional security, for those that think it necessary.

 

TinyPortal © 2005-2018