Another current Delphi user hoping to be an ex Delphi user

I’ll have to investigate further. Thanks for information.

I’ve started looking at WinForms and have discovered the fact that global variables are perhaps not the best things to use. I also would typically use multiple pas files with just code in, to segragate different parts of a project. Is there an example anywhere of a more substantial Elements DotNet Winforms project which uses more than one form (window) and more than one code module (file) so I can see how it all fits together.

Thanks

Also do you know if, during debug single step, hovering over an (e.g.) array variable, you get a display of the records of the array and their values? I use dynamic arrays a lot, and degugging these in Delphi works very well.

That works every time I use it. If you do find a case where it doesn’t let me know and I can fix it.

Thanks.

Another dumb(?) question … Why does btnOK.Text := ‘OK’ + 1 compile ok. Presumably it is auto casting the integer 1 to a string. This this correct in a strong typed system?

Also, I can’t see how to put methods in a separate pas file without hitting the “globals not allowed” error. I want to segregate different parts of functionality into different source files for ease of use.

Thanks again for your patience,

You can enable globals in the project options. By defautl they’re disabled (you can however add class methods in a clsas)

as for the integer, It’s not auto boxing it; but all strings support the + operator on “object” + “string” (and string + object). This will call ToString on it, as a convenient way to get the string value.

Yes, you are correct, there is a “learning curve” for WPF when you are familiar with the Delphi/WinForms approach, but what you get in the end is a hell of a lot better, and you end up writing a lot less code in WPF/.NET compared to Delphi.

1 Like

Agree with the “learning curve”, must say DevExpress WPF does helps a lot, but do not agree much with the less code. We use both and our Delphi “forms” are quite thin, probably because we do a big separation on GUI/logic related matters due to injection enforcements on the company.

We knew that MVVM (MVVC) idea sounded reasonable and there was this big push since silverlight for it but then after going deep into the process we realized that the ROI of that “evolution” was not on the same scale and that some enforcement of SOLID principles on our existing Delphi development was bringing the same benefit with less cost/effort.

We still maintain our venture on it, the few that endure the entire experience (like me) will say it is fine, but the people that joined, left and still kept in touch doesnt describe it as a joy ride as the Delphi way. Winforms has no space on this conversation :stuck_out_tongue: .

Thanks for all this feedback, it really helps. re WPF, all I need to do now is to sort out the problem of the “The type ‘Window’ does not support direct content” message, which although not preventing a compile, stops code completion, etc. from working, This occures when starting with an empty WPF project, then adding e.g. a StckFrame to the window in the designer. After a compile, the “wiggly” lines and error message goes away. but returns if the xaml test is edited in any way.

On the web there is reference to this problem - is it a VS2015 problem or Oxygene?

Re a previous question, I can’t figure how to set the main window properties from within code e,g,

namespace Bob001;

interface

uses
System.Collections.Generic,
System.Linq,
System.Windows,
System.Windows.Controls,
System.Windows.Data,
System.Windows.Documents,
System.Windows.Media,
System.Windows.Navigation,
System.Windows.Shapes;

type
Window1 = public partial class(System.Windows.Window)
private
method btnSet_Click(sender: System.Object; e: System.Windows.RoutedEventArgs);

method SetUp;

public
constructor;
end;

implementation

constructor Window1;
begin
InitializeComponent();
end;

method Window1.SetUp;
begin

end;

method Window1.btnSet_Click(sender: System.Object; e: System.Windows.RoutedEventArgs);
begin
Window1.HeightProperty := 200;
end;

end.

Window1.HeightProperty is a dependency property, and I have the same problem trying to set any other Window1 property. It must be simple, but I’m not seeing it.

So this does not only happen if you add more than one control, without a container, such as grid or a stack panel? You you literally see this on a fresh, untouched new project from template? (Oxygene, WPF Widows app, i assume)?

Udate: reproduced, will have that looked at, hopefully in time for the imminent 9.3 update.

Update 2: workaround is to simply build the project that makes the error go away. annoying and not proper fix, i agree.

method Window1.btnSet_Click(sender: System.Object; e: System.Windows.RoutedEventArgs);
begin
  Window1.HeightProperty := 200;
end;

Window1 is the class name, but you’re inside an instance. you’ll want just

method Window1.btnSet_Click(sender: System.Object; e: System.Windows.RoutedEventArgs);
begin
  HeightProperty := 200;
end;

else you’d be trying to set a static property on the Window1 type, which does not exist.

(Delphi adds global vars (named minus the T prefix) for each form, you can access “the form instance” by its name, so i can see where this pattern is coming from. But WPF does not, by default. That said, even in Delphi this’d be “wrong”, since the form instance you’d want to use “self” (which is implied) to modify the current form — not a global reference that might (or might now) refer to the same instance…

does that make sense?

Thanks, logged as bugs://78899 (for the WPF designer issue)

Wow! Not only do I get regular feedback re my problems, I actually find a bug!! Plus I get the feeling that the bug will be fixed soon. This is so unlike my previous Delphi experience :wink:

I will continue my journey with the trial software…

1 Like

You’re welcome :wink:

Hello Bob,

The “Window cannot have direct content” error is a problem in WPF template, missing System.Xaml.dll reference. Next build should have fixed template. But to fix the problem in your project you have to add reference to System.Xaml.dll into your project. Save it and restart VS. Please, let us know if you have any other problems with your project.

Hope that helps.

Aha. I did see a reference to that on the web. Tried and seems to have sorted the problrm out.

Thanks

OK. I’m now back in a WindowsForms project with Globals switched ON, I have the MainForm with a button on it. I typically delegate all procedures re that MainForm to another pas file (unit in Delphi) and manipulate all the objects on that form, and the form itself, from that unit file. In my current test project, in Main.pas I have

method MainForm.btnOK_Click(sender: System.Object; e: System.EventArgs);
begin
DoSetUp;
end;

The DoSetup method is in a separate file, RtnCommon.pas:

namespace BobWF001; // this is the same namespace as in Main.pas

interface

method DoSetUp;

implementation

method DoSetup;
begin
MainForm.btnOK.Text := ‘OK’;
MainForm.Height := 800;
end;

end.

The two lines in DoSetUp are the problem, so how do I reference the mainform and its objects from RtnCommon.pas? I’m obviously missing a fundamental here. Do I have to set a specific variable to hold the form (in Delphi “MainForm” would have been originally defined as TMainForm and MainForm: TMainForm would have been defined in the form pas file - I normally deleted this and created MyMainForm: TMainForm in the other unit pas file(s) associated with this form, and if that would work, is it the “correct” way here?

bugs://78899 got closed with status fixed.

The continuing journey as an “Ex” Delphi user …

I have looked again at the tutorials, and none seem to include the use of multiple pas files amd forms.

In any reasonable sized project, multiple forms and code files would be needed. The goal of separating GUI stuff from logic also demands the use of multiple code files. So far in my journey from Delphi I have seen glimpses of new opportunity, but I’m currently stuck on the fundamentals. I have a minimalist Delphi project that shows the fundamentals that I woud look for, and I have “imported” the files into a blank WinForms project to see how it wou;d look, but there are so many errors (not surprisingly) that it doesn’t really help.

I would be happy to help other Delphi people in documenting a simple Delphi project through to an Elements WinForms or WPF project - if this already exists, please let me know. Otherwise, I feel a bit stuck.

Not sure why will you split the code that is specific to setup the main form to another file but,
MainForm is the class name. You need to access the instance object.

You could do

method MainForm.btnOK_Click(sender: System.Object; e: System.EventArgs);
begin
DoSetUp(self);
end;

method DoSetUp(frm: MainForm);
implementation
method DoSetup(frm: MainForm);
begin
frm.btnOK.Text := ‘OK’;
frm.Height := 800;
end;

Also, you could create a helper class instead of global functions, and still have the code in another file, so you won’t need the parameter in DoSetup.

I woudn’t recommend creating global variables for each form, as in Delphi.

What exactly are you looking for, here?

  • to create more than one form: simply do Add New Item and add a second Window class to your project
  • to split (i assume a single class) into multiple source files: simply make sure its marked “partial”, and create a new file with the same class declaration, but different members.