Delphi 2007 - Error creating form: Failed to set data for...

Delphi 2007 - Error creating form: Failed to set data for...
The error message like this - "Error creating form: Failed to set data for..." appears on IDE CodeGear Delphi 2007 startup.
This situation occurs due to lack of access rights.
A simple and obvious half-measure is to run IDE CodeGear Delphi 2007 with administrator rights.
For example - check "Run this program as an administrator" in the "Compatibility" tab in Properties menu.

Delphi gives when starting "Socket error # 10038 Socket operation on non-socket"

Socket error # 10038 Socket operation on non-socket
"Socket error # 10038 Socket operation on non-socket" is a wide-spread error.
Access violation at address 205B90EA in module 'coreide270.bpl'. Read of address 00000000,
Next messages are "Access violation at address 205B90EA in module 'coreide270.bpl'. Read of address 00000000,", "Access violation at address 5005F8F4 in module 'rt1270.bpl. Read of address 00000000."
This erroneous behavior was noticed in Delphi RAD Studio 10.4 (10.4.1, 10.4.2).
Confirmed to work in Delphi 11.0 as well, with the obvious adjusts for version:
One can try these steps to fix Delphi 10.4:
  1. Shut the Delphi IDE down.
  2. Run Regedit.
  3. Go to the branch HKEY_CURRENT_USER\SOFTWARE\Embarcadero\BDS\21.0\KnownIDE Packages
  4. Find the value with name $(BDS)\Bin\LivePreview270.bpl and change the data from "Embarcadero FireUI Live Preview Package" to "_Embarcadero FireUI Live Preview Package" just adding one or two underscores in the beginning. Other symbols, for instance, I tried to put "#" will not fit, the erroneous behavior will not be fixed.
  5. Restart the Delphi IDE.
This is suitable for Delphi 11 as well, the branch in the system registry is HKEY_CURRENT_USER\SOFTWARE\Embarcadero\BDS\22.0\Known IDE Packages and value name $(BDS)\Bin\LivePreview280.bpl, value data to change is Embarcadero FireUI Live Preview Package
If one get these errors when starting up Delphi RAD Studio, one will have to do these operations every time one reinstall, add "Additional Options", etc.

PostMessage vs. SendMessage

What is the difference between PostMessage and SendMessage?

PostMessage is asynchronous, sends a message in the message queue associated with the thread and returns without waiting for the thread to process that messaage.
SendMessage is synchronous, calls the window procedure for the specified window and does not return until the window procedure has processed the message.

For loop using an enumeration Example from Learning Embarcadero Delphi

Learning Embarcadero Delphi. Free unaffiliated eBook created from Stack Overflow contributors
Educational Example is from "Learning Embarcadero Delphi" - Free unaffiliated eBook created from Stack Overflow contributors.
The example is on RIP Tutorial - For loop using an enumeration
The code example will not be compiled in Embarcadero Delphi, gives out two error messages, one of them is:
"[dcc32 Error] EnumLoop.dpr(14): E2430 for-in statement cannot operate on collection type 'TWeekdays'" program EnumLoop; uses TypInfo; type TWeekdays = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday); var wd : TWeekdays; begin for wd in TWeekdays do WriteLn(GetEnumName(TypeInfo(TWeekdays), Ord(wd))); end.
The error explanation from docwiki Embarcadero
E2430 for-in statement cannot operate on collection type '%s' (Delphi) Go Up to Error and Warning Messages (Delphi) A for-in statement can only operate on the following collection types: Primitive types that the compiler recognizes, such as arrays, sets or strings Types that implement IEnumerable Types that implement the GetEnumerator pattern as documented in the Delphi Language Guide Ensure that the specified type meets these requirements.
To make the example to work, replace with this line: for wd := Low(TWeekdays) to High(TWeekdays) do
The example was tested in CodeGear Delphi 2007, Embarcadero Delphi 10.4.2 Sydney, Embarcadero Delphi 11.3 Alexandria

Having worked through the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, I naively thought that I knew Python

Head First Python, 2nd Edition by Paul Barry
Having worked through the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016 (Publisher(s): O'Reilly Media, Inc.), I naively thought that I knew Python,

Mike McGrath Python in Easy Steps 2013
But when I started reading Mike McGrath Python in Easy Steps I realized that I don’t even know all the keywords of the Python language. import keyword for word in keyword.kwlist: print(word)

When one reaches the chapter — "Processing requests", there will be problems with Abyss Web Server, the settings made according to the official guide will not help: Adding Python Support.

All examples from the book work when leaving the page ".html" to ".py" page, parameters are passed and everything is displayed.

However, then suddenly everything stops working, even those examples that just worked, when trying to pass something from ".html" to ".py", Abyss Web Server gives the 500 error.

The record in the log: "AttributeError: partially initialized module 'cgi' has no attribute 'FieldStorage' (most likely due to a circular import)."

GUIs with Tkinter (and Fun with Turtles)

Python Turtle Graphics
Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzig and Seymour Papert in 1966.

The example that comes with the turtle docs:

from turtle import * color('purple', 'cyan') begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done()

The example was found in the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, Publisher(s): O'Reilly Media, Inc.

Getting UserAgent and Browser name in Flask, Python

Head First Python, 2nd Edition by Paul Barry
Inspired by the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, Publisher(s): O'Reilly Media, Inc.
where some examples don't work
Pages 296-300 of that book

Task 4: Create Code to Work with Our Webapp’s Database and Tables


Determine the Flask version.
First way: two lines in IDLE import flask print(flask.__version__) Second way: one command in Command line: pip show flask The installed Flask version is uptodate - 3.0.3
Determine the Python version.
First way: two lines in IDLE from platform import python_version python_version() Second way: one command in Command line again: python -V The installed Python version is uptodate too - 3.12.3
Coding in Python, Flask from flask import Flask from flask import render_template, request The method request.user_agent.browser returns nothing.
The next method requires one more importing from ua_parser import user_agent_parser
These three lines returns the browser name in browser variable: web_detail = str(request.user_agent) user_browser = user_agent_parser.ParseUserAgent(web_detail) browser = user_browser['family'] or briefer in single code line user_agent_parser.Parse(request.user_agent.string)['user_agent']['family'] I digress a little from the main trend of this note and give a method that receives all the User Agent: request.headers.get("user-agent")

Summing up, at the beginning, I believed the problem was that
"request.user_agent.browser" did not return anything and found other methods to get the browser name. But still nothing was written to the database. I couldn't write to the field "browser_string" in the table "log" of the database "vsearchlogDB" anything, the value after insert operation was Null

How to Fix ImportError: cannot import name 'escape' from

Head First Python, 2nd Edition by Paul Barry
ImportError: cannot import name 'escape' from 'flask'
or
ImportError: cannot import name 'escape' from 'jinja2'
There is no possibility to import name 'escape' from 'flask' (or jinja2).
Today the simplest way is to use from markupsafe import escape instead of from flask import escape.

Jinja is a dependency of Flask and Flask V1.X.X uses the escape module from Jinja, however support for the escape module was dropped in newer versions of Jinja.

Markup and escape should be imported from MarkupSafe.
from flask import escape was found on the page in the article It’s Time to Escape (Your Data) in the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, Publisher(s): O'Reilly Media, Inc.

Swapping two variables without using another variable (Arithmetic Operator)

Swapping two variables without using another variable (Arithmetic Operator)
a = 5 b = 10 a = a + b b = a - b a = a - b print(a, b) 10 5
I found this algorithm interesting.
Example made in Python

Three ways how to add a favicon in uniGui

A favicon (/ˈfæv.ɪˌkɒn/; short for favorite icon), also known as a shortcut icon, website icon, tab icon, URL icon, or bookmark icon, is a file containing one or more small icons associated with a particular website or web page.
In March 1999, Microsoft released Internet Explorer 5, which supported favicons for the first time. Originally, the favicon was a file called favicon.ico placed in the root directory of a website. It was used in Internet Explorer's favorites (bookmarks) and next to the URL in the address bar if the page was bookmarked.
Taken from Wikipedia

To add an icon to the site one must place an ico format file named favicon.ico in the root directory of the site.
But the uniGUI site does not have a root directory. Placing favicon.ico in the module directory does nothing.
This problem can be solved in various ways.

The Viber Analyzer on uniGui project and Embarcadero Delphi 10.4.1 Sydney are used as an example.


The first way is the most obvious.
Since web application is coded in Delphi, one can add an icon to it, like to an ordinary program.
The icon can be set in the Project->Options...->Application->Icons->Application Icon Settings->Icon.
And this icon will be the site icon.

Viber Analyzer on uniGui ScreenShot in Delphi

Viber Analyzer on uniGui ScreenShot
After compiling the project and refreshing the page in the browser, the icon is as needed.
Viber Analyzer on uniGui ScreenShot in Delphi

The second way is a solution from the uniGUI.
A uniGui project has one specialized data module - TUniGUIServerModule.
This is a singleton object that implements server-side functions of a web application.
This module is in the forms list, one must select this module, find the "Favicon" property in the object inspector and load the icon into it.

Viber Analyzer on uniGui Server ScreenShot
UniGUI Server also changes its icon.
The UniGUI Server icon in the property of Windows application, which is visible, for example, in Windows Explorer, is taken from the Project Options in Delphi

The third way is one line of code in the OnBeforeInit event handler in the TUniGUIServerModule successor.
Now, on launching a web application, the icon will be loaded from an external file, and if missing, the icon can added by one of two ways previously described.
procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender: TObject);
begin
  try
    Favicon.LoadFromFile('favicon.ico');
  except
  end;
end;
or
procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender: TObject);
begin
  try
    TUniGUIServerModule(Sender).Favicon.LoadFromFile('favicon.ico');
  except
  end;
end;