AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Delphi-PRAXiS - Lounge Delphi-News aus aller Welt Use ChatGPT to Convert Other Language Source Code to Delphi
Thema durchsuchen
Ansicht
Themen-Optionen

Use ChatGPT to Convert Other Language Source Code to Delphi

Ein Thema von DP News-Robot · begonnen am 12. Feb 2023
Antwort Antwort
Benutzerbild von DP News-Robot
DP News-Robot

Registriert seit: 4. Jun 2010
15.473 Beiträge
 
#1

Use ChatGPT to Convert Other Language Source Code to Delphi

  Alt 12. Feb 2023, 23:40
If you've read some of my previous posts you know how much I've struggled to make the paradigm shift from being a top-down, procedural programmer to an OOP programmer. I've purchased several books on OOP. And one book series I thought would hold some promise are "The Object-Oriented Thought Process" books written by Matt Weisfeld. I have four different editions on my book shelf.
I struggle with OOP for several reasons. One very frustrating reason is the lack of Delphi/Pascal examples used by authors. Most of the code examples are written in Java, or C, or C# or some language other than Delphi/Pascal.

The last bullet point on page 3 of Weisfled's fourth edition, listed under the heading of "What's New in the Fourth Edition", states:


  • Expanded code examples, for certain chapters, in Java, C# .NET, VB .NET, and Objective-C available online on the publisher's website


No Object Pascal or Delphi examples!

No Object Pascal or Delphi examples. I reached out to Weisfeld asking if he might include Object Pascal examples and received a negative response.

I love Pascal. It's elegant. It's easy to read and understand. I've been using Pascal/Delphi since 1985. (2023-1985=38 years). Besides SQL, it's my main programming language. Ok, I confess, I did Active Server Pages (APS) and VB Script for about 10 years.

I've tried loading Java onto my machine so I could follow along and learn the OOP concepts but I just can't wrap my head around the Java syntax.

Today, I discovered the answer that works for me. ChatGPT!

I asked ChatGPT to convert the following code from page 24 of "The Object-Oriented Thought Process" to Delphi and the results were very hopeful.

public class IntSquare {

// private attribute
private int squareValue;

//public interface
public in getSquare (int value) {

squareValue = calculateSquare(value);
return SquareValue

}

//private implementation
private int calculation (int value) {
return Math.pow(value,2);
}
} Here are the results returned from ChatGPT:

type
TIntSquare = class
private
FSquareValue: Integer;
function CalculateSquare(value: Integer): Integer;
public
function GetSquare(value: Integer): Integer;
end;

implementation

function TIntSquare.CalculateSquare(value: Integer): Integer;
begin
Result := value * value;
end;

function TIntSquare.GetSquare(value: Integer): Integer;
begin
FSquareValue := CalculateSquare(value);
Result := FSquareValue;
end;

end. I know the results are not the indented and formatted code you would get from inside the IDE. This was my first attempt at using ChatGPT. I took several screen shots of my interaction with ChatGPT so I can show you what happened.

Here is my entire ChatGPT session:















Here is the final output from ChatGPT.

uses
System.Math;

type
TIntSquare = class
private
FSquareValue: Integer;
function GetSquareValue: Integer;
procedure SetSquareValue(const Value: Integer);
function CalculateSquare(value: Integer): Integer;
public
property SquareValue: Integer read GetSquareValue write SetSquareValue;
function GetSquare(value: Integer): Integer;
end;

implementation

function TIntSquare.CalculateSquare(value: Integer): Integer;
begin
Result := Round(Power(value, 2));
end;

function TIntSquare.GetSquare(value: Integer): Integer;
begin
SquareValue := CalculateSquare(value);
Result := SquareValue;
end;

function TIntSquare.GetSquareValue: Integer;
begin
Result := FSquareValue;
end;

procedure TIntSquare.SetSquareValue(const Value: Integer);
begin
FSquareValue := Value;
end;

end.This looks very promising! Give ChatGPT a try converting code.
https://openai.com/blog/chatgpt/


Enjoy!
Semper Fi
Gunny Mike https://zilchworks.com





Weiterlesen...
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:42 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz