Delphi: Screen Scraping

function GetFocusedText(Wnd: HWND): string;
var
  str: string;
  Len: Integer;
begin
  str := '';
  if Wnd <> 0 then
  begin
    Len := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
    if Len > 0 then
    begin
      SetLength(str, Len);
      Len := SendMessage(Wnd, WM_GETTEXT, Len+1, LPARAM(PChar(str)));
      SetLength(str, Len);
    end;
  end;
  Result := str;
end;

Very good screen scraping article for C++

Quake III Fast Inverse Square Root

John Carmack’s Quake 3 source code in C:

float Q_rsqrt( float number )
{
	long i;
	float x2, y;
	const float threehalfs = 1.5F;
 
	x2 = number * 0.5F;
	y  = number;
	i  = * ( long * ) &y;                       // evil floating point bit level hacking
	i  = 0x5f3759df - ( i >> 1 );               // what the f**k? 
	y  = * ( float * ) &i;
	y  = y * ( threehalfs - ( x2 * y * y ) );   // 1st iteration
//	y  = y * ( threehalfs - ( x2 * y * y ) );   // 2nd iteration, this can be removed
 
	return y;
}

Toon Krijthe’s Delphi (Object-Pascal) version:

function rsqrt(const ANumber: Single): Single;
var
  ResultAsInt: UInt32 absolute Result;
begin
  Result := ANumber;
  ResultAsInt := $5F3759DF - (ResultAsInt shr 1);
  Result := Result * ( 1.5 - (ANumber * 0.5 * Result * Result));     // 1st iteration
//  Result := Result * ( 1.5 - (ANumber * 0.5 * Result * Result));   // 2nd iteration, this can be removed
end;

Why C# coders should shut up about Delphi

Jon L. Aasenden

EDIT: Some 3 years after this satire post was published, a website called “.NetRocks” decided to make a number out of it. The satire clearly went over their heads, and the facts I outline in the post was met with ridicule. I’m a bit disappointed with .NetRocks, because this could have been a great opportunity for them to learn more about modern object-pascal development and it’s ecosystems. They seem genuinely baffled that Delphi and Object-Pascal in general was being used in 2016 (and 2019), and their behavior and response demonstrates the very arrogance and ignorance we have come to expect from “brogrammers” of their type.

I must admit that I’m somewhat shocked that a massive show like .NetRocks is utterly ignorant of the fact that Object-Pascal as a language has millions of users around the world. You have compilers like Oxygene from RemObjects that targets .Net, Java, x86, ARM and WebAssembly…

View original post 4,832 more words

Delphi vs Alternatives

Broad comparison of programming environments (IDE’s) with internal GUI support:

  • Delphi / C++ Builder Community Edition (WINNER)
    • Free (for yearly income under $5000)
    • Small executable file
    • Very fast execution
    • Very fast compiling
    • No external software requirement
    • Good Cross-Platform support
  • Visual Studio
    • Free
    • Small executable file
    • Very fast execution
    • Fast compiling
    • External software requirement (.Net Framework)
    • Very Bad Cross-Platform support (Xamarin sucks)
  • Qt
    • Only free for open source projects
    • Very large executable file
    • Fast execution
    • Slow compiling
    • No external software requirement
    • Very good Cross-Platform support
  • Java
    • Free (with limitations)
    • Small executable file
    • Slow execution
    • Slow compiling
    • External software requirement (Java Virtual Machine)
    • Good Cross-Platform support

How to Install GLUT to Dev C++

GLUT is a platform-independent OpenGL library. We need to follow the steps below in order to use it on Dev C++

  • glut.h – Copy to C:Dev-CppincludeGL
  • glut32.def – Copy to C:Dev-Cpplib
  • glut32.dll – Copy to C:WINDOWSsystem32

 

Let’s try it:

#include <glgl.h>
#include <glglut.h>
void init(void);
void display(void);

int main(int argc, char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(250,250);
glutInitWindowPosition(100,200);
glutCreateWindow("My OpenGL Application");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

void init(void)
{
glClearColor(0.0f ,0.0f ,0.0f ,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)250/(GLfloat)250,0.1f,100.0f);
}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0f, 1.0f, -10.0f);
glVertex3f(-1.0f,-1.0f, -10.0f);
glVertex3f( 1.0f,-1.0f, -10.0f);
glEnd();
glutSwapBuffers();
}