-
Content Count
116 -
Joined
-
Last visited
Everything posted by bravesofts
-
Try use OLEDB (using AdoConnection) rather using ODBC
-
i update the class my github Repo here unit API.Utils; interface uses System.SysUtils, // [Exceptions] System.Generics.Defaults; // [IComparer, TComparer] type TRange<T> = class public // Check if a value is within the range [aMin, aMax] using a custom comparer class function IsIn(const aValue, aMin, aMax: T; const aComparer: IComparer<T>): Boolean; overload; static; // Check if a value is within the range [aMin, aMax] using the default comparer class function IsIn(const aValue, aMin, aMax: T): Boolean; overload; static; end; implementation { TRange<T> } class function TRange<T>.IsIn(const aValue, aMin, aMax: T; const aComparer: IComparer<T>): Boolean; begin case GetTypeKind(T) of tkString, tkClass, tkLString, tkWString, tkInterface, tkDynArray, tkUString: begin if PPointer(@aValue)^ = nil then Exit(False); end; tkMethod: begin if (PMethod(@aValue)^.Data = nil) or (PMethod(@aValue)^.Code = nil) then Exit(False); end; tkPointer: if PPointer(@aValue)^ = nil then Exit(False); end; if not Assigned(aComparer) then raise EArgumentNilException.Create('Comparer is not assigned.'); Result := (aComparer.Compare(aValue, aMin) >= 0) and (aComparer.Compare(aValue, aMax) <= 0); end; class function TRange<T>.IsIn(const aValue, aMin, aMax: T): Boolean; begin Result := IsIn(aValue, aMin, aMax, TComparer<T>.Default); end; end. the call test : program RangeCheckerPrj; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, DateUtils, System.Types, System.Generics.Defaults, API.Utils in 'API\API.Utils.pas', API.Objects.Comparer in 'API\API.Objects.Comparer.pas', API.RangeCheckerTest in 'API\API.RangeCheckerTest.pas'; begin try Writeln('-----------------<< Integer Tests >>--------------------------------'); Writeln(TRangeTester<Integer>.Test(5, 1, 10)); // "5 is within the range [1, 10]" Writeln(TRangeTester<Integer>.Test(15, 1, 10)); // "15 is outside the range [1, 10]" Writeln('-----------------<< Int64 Tests >>--------------------------------'); Writeln(TRangeTester<Int64>.Test(5_000_000_000_000_000_001, 5_000_000_000_000_000_000, 5_000_000_000_000_000_010)); Writeln(TRangeTester<Int64>.Test(5_000_000_000_000_000_000, 5_000_000_000_000_000_001, 5_000_000_000_000_000_010)); Writeln('-----------------<< Float Tests >>----------------------------------'); Writeln(TRangeTester<Double>.Test(7.5, 5.0, 10.0)); Writeln(TRangeTester<Double>.Test(7.5, 7.6, 10.0)); Writeln('-----------------<< DateTime Tests >>------------------------------'); Writeln(TRangeTester<TDateTime>.Test(Today, Today, Today +10)); Writeln(TRangeTester<TDateTime>.Test(Yesterday, Today, Today +10)); Writeln('-----------------<< String Tests >>--------------------------------'); Writeln(TRangeTester<string>.Test('hello', 'alpha', 'zulu')); Writeln(TRangeTester<string>.Test('zulu', 'alpha', 'omega')); Writeln(TRangeTester<string>.Test('b', 'a', 'c')); // "'b' is within the range ['a', 'c']" Writeln(TRangeTester<string>.Test('A', 'b', 'c')); Writeln(TRangeTester<string>.Test('B', 'a', 'c')); Writeln('-----------------<< TPoint Tests >>-----------------------------'); Writeln(TRangeTester<TPoint>.Test(gPoint1, gPoint2, gPoint3, PointComparer)); Writeln(TRangeTester<TPoint>.Test(Point(5, 5), Point(0, 0), Point(3, 4), PointComparer)); Writeln('-----------------<< TCustomRecord Tests >>-----------------------------'); Writeln(TRangeTester<ICustomRecord>.Test(gRec1, gRec2, gRec3, gRecordComparer)); gRec1.New.Edit('Mid', 40); Writeln(TRangeTester<ICustomRecord>.Test(gRec1, gRec2, gRec3, gRecordComparer)); Writeln('-----------------<< TProduct Tests >>-----------------------------'); Writeln(TRangeTester<IProduct>.Test(gProduct1, gProduct2, gProduct3, gProductComparer)); gProduct1.New.Edit(1, 40); Writeln(TRangeTester<IProduct>.Test(gProduct1, gProduct2, gProduct3, gProductComparer)); Writeln('-----------------<< TClient Tests >>-----------------------------'); Writeln(TRangeTester<IClient>.Test(gClient1, gClient2, gClient3, gClientComparer)); gClient1.New.Edit('Alice', 40); Writeln(TRangeTester<IClient>.Test(gClient1, gClient2, nil, gClientComparer)); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. the Output:
-
Vcl text box that user can move/resize at runtime?
bravesofts replied to Paul Dardeau's topic in VCL
try use this here: TSizeControl the github code here: Github Code any updates i will post it here, if possible -
how to set delphi android app's idsig file, why my app can not be installed?
bravesofts replied to tomye's topic in Cross-platform
Resolving .idsig Issues in Delphi Android Apps Understand the .idsig File Role The .idsig file is generated during APK signing with APK Signature Scheme V2/V3. It ensures APK integrity. Deleting it forces fallback to legacy signing (V1). Update Your SDK Tools Use the latest Android SDK and Build Tools compatible with Delphi. Ensure Android SDK Build Tools 30.0.0 or higher is installed. Verify SDK paths in Tools > Options > SDK Manager. Prevent App Disappearance After Reboot Ensure consistent and trusted APK signing with a proper keystore. Avoid modifying the APK (e.g., deleting .idsig) after signing. Test on Multiple Devices Test your app on various devices and Android versions, focusing on 7.0 and above. Check for Manufacturer-Specific Issues Investigate device-specific forums for issues with customized Android versions. Use Logcat for Debugging Gather installation/runtime logs using: adb shell logcat | grep "com.yourCompany.yourAppName" Share the log file with us here for further analysis. *Always use at least Android SDK Build Tools 30.0.0 or higher to avoid outdated signing issues.* -
Would you consider adding some video tutorials on how to use Bold? It would be very helpful if the demo databases were PostgreSQL, SQLite, or even Paradox, as this would make it easier to understand the entire concept at once.
-
fix stretched splash 🔥 Delphi Android Tip: Fix Stretched Splash Images in Your Delphi Apps! 🚀
bravesofts posted a topic in I made this
Hey Delphi developers! If you've ever generated Android splash screen images using Delphi IDE and noticed they appear **stretched**, here's a simple way to fix that and ensure your splash image is always **centered without distortion**. ### Steps to Fix It: ) After building your project, go to the following paths where the splash screen files are generated: if your target android system is 64bit: <YourProjectDirectory>\Android64\Debug\<YourProjectName>\res\drawable <YourProjectDirectory>\Android64\Debug\<YourProjectName>\res\drawable-anydpi-v21 or <YourProjectDirectory>\Android\Debug\<YourProjectName>\res\drawable <YourProjectDirectory>\Android\Debug\<YourProjectName>\res\drawable-anydpi-v21 Copy both files **`splash_image_def.xml | splash_image_def-v21.xml`** from this folder and paste it into a new directory in your project (e.g., **`YourProjectDirectory\res\theme`**). 2 Open both files in Delphi IDE and add the following line inside each file: android:scaleType="centerInside" 3 Deployment: Go to Project > Deployment in Delphi IDE. Select all configurations for your target system. Click on the column header "Local Name" to sort the list by name. Scroll down, find the default splash xml files, uncheck them, and replace them with your newly edited files. Don’t forget to set the remote path for the new files according to the unchecked ones. That’s it! Clean&Rebuild and deploy your project, and you’ll see your splash image properly centered on all devices without any stretching! ------------------------------------------------------------------------------------------------- I hope Embarcadero adds this by default in an upcoming version to fix the issue. ------------------------------------------------------------------------------------------------- Hope this helps, and happy coding! If you have questions, feel free to drop them below.- 3 replies
-
- android splash
- fmx
-
(and 1 more)
Tagged with:
-
fix stretched splash 🔥 Delphi Android Tip: Fix Stretched Splash Images in Your Delphi Apps! 🚀
bravesofts replied to bravesofts's topic in I made this
Not yet... I wish someone could do it for me. I do have an account there, but the website’s interface is far from user-friendly.!!- 3 replies
-
- android splash
- fmx
-
(and 1 more)
Tagged with:
-
I've been diving deep into Embarcadero's Androidapi.JNI units, especially Androidapi.JNIBridge, and I'm truly amazed by the software design. The implementation of TJavaGenericImport showcases an incredibly high level of abstraction and modularity, making it both elegant and powerful. The way these units bridge Delphi with Java is nothing short of genius. I can't help but wonder who the developer (or team) was behind this architectural masterpiece. Does anyone know who contributed to these units? Or perhaps some background on the development process for this part of the RTL? I'm keen to learn more about the design philosophy and the thought process that led to such an outstanding implementation.
-
variadic-arguments How to create a Delphi variadic method similar to Write/Writeln without requiring brackets for arguments?
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
Temporary Solution: By using Delphi's TValue type from the System.Rtti unit, I was able to implement a robust custom Writeln procedure usin overload. Here's how it works: Main Procedure to Process Arguments This procedure processes the arguments, determining their types and formatting them as needed: procedure DoCustomWriteln(const Args: array of TValue); var LArg: TValue; LOutput: string; I: Integer; begin LOutput := ''; for I := Low(Args) to High(Args) do begin LArg := Args[I]; case LArg.Kind of tkInteger: LOutput := LOutput + IntToStr(LArg.AsInteger); tkFloat: LOutput := LOutput + FloatToStr(LArg.AsExtended); tkString, tkLString, tkUString, tkWString: LOutput := LOutput + LArg.AsString; tkChar, tkWChar: LOutput := LOutput + LArg.AsString; tkVariant: try LOutput := LOutput + VarToStr(LArg.AsVariant); except LOutput := LOutput + '<invalid variant>'; end; else LOutput := LOutput + '<unsupported type>'; end; // Add a separator unless it's the last argument if I < High(Args) then LOutput := LOutput + ', '; end; Writeln(LOutput); end; Overloading Writeln To make calling this function straightforward without requiring brackets, I created multiple overloads for the CustomWriteln procedure: procedure CustomWriteln(A1: TValue); overload; begin DoCustomWriteln([A1]); end; procedure CustomWriteln(A1, A2: TValue); overload; begin DoCustomWriteln([A1, A2]); end; procedure CustomWriteln(A1, A2, A3: TValue); overload; begin DoCustomWriteln([A1, A2, A3]); end; // Add more overloads as needed for additional parameters Test in Project: begin try // Examples of usage with different types CustomWriteln(42); CustomWriteln(3.14, 'Hello'); CustomWriteln(1, 2.2, 'Text', True); CustomWriteln(1, 'Two', 3.3, 'Four', False, 6); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. Example Output ------- 42 3,14, Hello 1, 2,2, Text, <unsupported type> 1, Two, 3,3, Four, <unsupported type>, 6 Advantages of This Approach: Flexible Input: Handles integers, floats, strings, characters, and variants. Type-Safe: Uses TValue to handle types dynamically. Scalable: Easy to extend by adding more overloads or enhancing DoCustomWriteln. --- Final Project: program CustomWritelnProj; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, System.Variants, System.Math, System.Rtti; procedure DoCustomWriteln(const Args: array of TValue); var LArg: TValue; LOutput: string; I: Integer; begin LOutput := ''; for I := Low(Args) to High(Args) do begin LArg := Args[I]; case LArg.Kind of tkInteger, tkInt64: LOutput := LOutput + LArg.AsInt64.ToString; tkFloat: LOutput := LOutput + LArg.AsExtended.ToString; tkEnumeration: LOutput := LOutput + BoolToStr(LArg.AsBoolean, True); tkString, tkLString, tkUString, tkWString, tkChar, tkWChar: LOutput := LOutput + LArg.AsString; tkVariant: try LOutput := LOutput + LArg.AsVariant.ToString; except LOutput := LOutput + '<invalid variant>'; end; else LOutput := LOutput + '<unsupported type>'; end; // Add a separator unless processing the last element if I < High(Args) then LOutput := LOutput + ', '; end; Writeln(LOutput); end; // Overloaded CustomWriteln implementations procedure CustomWriteln(A1: TValue); overload; begin DoCustomWriteln([A1]); end; procedure CustomWriteln(A1, A2: TValue); overload; begin DoCustomWriteln([A1, A2]); end; procedure CustomWriteln(A1, A2, A3: TValue); overload; begin DoCustomWriteln([A1, A2, A3]); end; procedure CustomWriteln(A1, A2, A3, A4: TValue); overload; begin DoCustomWriteln([A1, A2, A3, A4]); end; procedure CustomWriteln(A1, A2, A3, A4, A5: TValue); overload; begin DoCustomWriteln([A1, A2, A3, A4, A5]); end; procedure CustomWriteln(A1, A2, A3, A4, A5, A6: TValue); overload; begin DoCustomWriteln([A1, A2, A3, A4, A5, A6]); end; procedure CustomWriteln(A1, A2, A3, A4, A5, A6, A7: TValue); overload; begin DoCustomWriteln([A1, A2, A3, A4, A5, A6, A7]); end; procedure CustomWriteln(A1, A2, A3, A4, A5, A6, A7, A8: TValue); overload; begin DoCustomWriteln([A1, A2, A3, A4, A5, A6, A7, A8]); end; procedure CustomWriteln(A1, A2, A3, A4, A5, A6, A7, A8, A9: TValue); overload; begin DoCustomWriteln([A1, A2, A3, A4, A5, A6, A7, A8, A9]); end; begin try // Examples of usage with different types CustomWriteln(42); CustomWriteln(MaxComp,'The max value of Int64'); CustomWriteln(MaxComp,MinComp, 'Int64 Interval'); CustomWriteln(1, 2.2, 'Text', True); CustomWriteln(1, 'Two', 3.3, 'Four', False, 6); except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; Readln; end. -
i have base interface: type iBaseFoo = interface BaseMethod1; BaseMethod2; BaseMethod3; end; iTestFoo = interface(ibaseFoo) TestFooMethod; end; -- TBaseFoo = class(TInterfacedObject, iBaseFoo) private // some code here protected BaseMethod1; BaseMethod2; BaseMethod3; end; TTestFoo = class(TBaseFoo, ITestFoo) // how to Ensures TTestFoo inherits IBaseFoo methods from TBaseFoo, avoiding re-implementation. procedure TestFooMethod; end; -- my question is: How can I ensure that TTestFoo (or any descendant of TBaseFoo) uses the IBaseFoo method implementations provided by TBaseFoo, without re-implementing these methods in every descendant class?
- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
I finally managed to update the code to exactly what I needed: My Github Updated Example- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
I guess I'm not okay today, haha. Maybe I'm just lacking coffee or in need of some rest. Anyway, thank you, everyone!- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
I apologize for the delay and also for the code full of errors above. I hope this example is easy to understand. Thank you Github Example Link- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
Give me a maximum of an hour; I'm working on it and will provide a very simple, working example that can be easily understood- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
I understand the code above is a bit long, but I’d like to keep it to ensure the example can be compiled fully. It provides the necessary context for the issue. If you don’t mind, I’d prefer to leave it here.- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
unit Model.DB.Exceptions; interface uses System.SysUtils; type EDatabaseError = class(Exception); EInvalidParameterError = class(EDatabaseError); EConnectionError = class(EDatabaseError); implementation end. ---- Unit Model.Firedac.ParamsTypes; interface uses System.Classes, System.Generics.Collections; type {$REGION ' Firedac Connection Params .. '} {$REGION ' DriverName Param & DataType .. '} TDriverFDTypeEnum = (dtAccessDB, dtSqlite, dtPostgreSql, dtMySQL, dtFirebird, dtInterbase, dtInterbaseLite); TDriverFDTypeEnumHelper = record helper for TDriverFDTypeEnum public function ToString: string; function GetDriverName: string; end; TBaseFiredacDriver = class protected class function DBName(const aValue: TDriverFDTypeEnum): string; static; class function DriverName(const aValue: TDriverFDTypeEnum): string; static; end; TMSAccessDriver = class(TBaseFiredacDriver) end; TSQLiteDriver = class(TBaseFiredacDriver) end; TPostgreSqlDriver = class(TBaseFiredacDriver) end; TMySQLDriver = class(TBaseFiredacDriver) end; TFirebirdDriver = class(TBaseFiredacDriver) end; TInterbaseDriver = class(TBaseFiredacDriver) end; TInterbaseLiteDriver = class(TBaseFiredacDriver) end; {$ENDREGION} {$REGION ' SQLite Params .. '} TSQLiteLockingMode = (mLockingExclusive, mLockingNormal); TSQLiteLockingModeHelper = record helper for TSQLiteLockingMode public function ToString: string; end; TSQLiteEncryptMode = (EncryptNone, AES128, AES192, AES256, AES_CTR128, AES_CTR192, AES_CTR256, AES_ECB128, AES_ECB192, AES_ECB256); TSQLiteEncryptModeHelper = record helper for TSQLiteEncryptMode public function ToString: string; class function FromString(const aValue: string): TSQLiteEncryptMode; static; end; {$ENDREGION} TFDRemoteBy = (FlatFile, Remote, Custom); TFDRemoteByHelper = record helper for TFDRemoteBy public function ToString: string; end; {$ENDREGION} implementation uses System.SysUtils, Model.DB.Exceptions; {$REGION ' Driver FireDac Type Helper.. '} function TDriverFDTypeEnumHelper.ToString: string; const cDBTypeNames: array [TDriverFDTypeEnum] of string = ( 'MSAccess', 'SQLite', 'PostgreSQL', 'MySQL', 'Firebird', 'Interbase', 'Interbase Lite' ); begin Result := cDBTypeNames[Self]; end; function TDriverFDTypeEnumHelper.GetDriverName: string; const cDBDriverNames: array [TDriverFDTypeEnum] of string = ( 'MSAcc', 'SQLite', 'PG', 'MySQL', 'FB', 'IB', 'IBLite' ); begin Result := cDBDriverNames[Self]; end; {$ENDREGION} {$REGION ' SQLite Locking Mode Helper .. '} function TSQLiteLockingModeHelper.ToString: string; const cLockingModeNames: array [TSQLiteLockingMode] of string = ( 'Exclusive','Normal' ); begin Result := cLockingModeNames[Self]; end; {$ENDREGION} {$REGION ' SQLite Encrypt Mode Helper .. '} function TSQLiteEncryptModeHelper.ToString: string; const cEncryptModeNames: array [TSQLiteEncryptMode] of string = ( 'No', 'aes-128', 'aes-192', 'aes-256', 'aes-ctr-128', 'aes-ctr-192', 'aes-ctr-256', 'aes-ecb-128', 'aes-ecb-192', 'aes-ecb-256' ); begin Result := cEncryptModeNames[Self]; end; class function TSQLiteEncryptModeHelper.FromString(const aValue: string): TSQLiteEncryptMode; var LEncryptMode: TSQLiteEncryptMode; begin for LEncryptMode := Low(TSQLiteEncryptMode) to High(TSQLiteEncryptMode) do if SameText(aValue, LEncryptMode.ToString) then Exit(LEncryptMode); raise EInvalidParameterError.CreateFmt('Invalid encryption mode: %s', [aValue]); end; {$ENDREGION} {$REGION ' FireDac RemoteBy Helper .. '} function TFDRemoteByHelper.ToString: string; const cFDRemoteByNames: array [TFDRemoteBy] of string = ( 'FlateFile', 'Remote', 'Custom' ); begin Result := cFDRemoteByNames[Self]; end; {$ENDREGION} { TBaseFiredacDriver } class function TBaseFiredacDriver.DBName( const aValue: TDriverFDTypeEnum): string; begin Result := aValue.ToString; end; class function TBaseFiredacDriver.DriverName( const aValue: TDriverFDTypeEnum): string; begin Result := aValue.GetDriverName; end; end. ---- unit Model.FiredacParams.BaseInterface; interface uses Model.Firedac.ParamsTypes; type iBaseFDParams<TDBType: TBaseFiredacDriver> = interface ['{B5A4A031-EFA0-4424-902D-2529FC4F1B48}'] function Pooled(aValue: Boolean): iBaseFDParams<TDBType>; overload; function Database(aValue: string): iBaseFDParams<TDBType>; overload; function Username(aValue: string): iBaseFDParams<TDBType>; overload; function Password(aValue: string): iBaseFDParams<TDBType>; overload; // function MonitorBy(aValue: TFDRemoteBy): iBaseFDParams<TDriverFDType>; overload; function Pooled: Boolean; overload; function Database: string; overload; function UserName: string; overload; function Password: string; overload; // function MonitorBy: TFDRemoteBy; overload; function Params: iBaseFDParams<TDBType>; end; implementation end. ---- The code provided above contains necessary units used by my main unit below (Model.Firedac.ConnectionParams), where the actual issue occurs. unit Model.Firedac.ConnectionParams; interface uses System.Classes, System.SysUtils, System.Generics.Collections, // Model.Firedac.ParamsTypes, Model.FiredacParams.BaseInterface, Model.DB.Exceptions; type iMSAccesseParams = iBaseFDParams<TMSAccessDriver>; iSQLiteParams = interface (iBaseFDParams<TSQLiteDriver>) function LockingMode(aValue: TSQLiteLockingMode): iBaseFDParams<TSQLiteDriver>; overload; function Encrypt(aValue: TSQLiteEncryptMode): iBaseFDParams<TSQLiteDriver>; overload; function LockingMode: TSQLiteLockingMode; overload; function Encrypt: TSQLiteEncryptMode; overload; end; iPostgreSqlParams = iBaseFDParams<TPostgreSqlDriver>; iMySQLParams = iBaseFDParams<TMySQLDriver>; iFirebirdParams = iBaseFDParams<TFirebirdDriver>; iInterbaseParams = iBaseFDParams<TInterbaseDriver>; iInterbaseLParams = iBaseFDParams<TInterbaseLiteDriver>; function GetDefault_SqliteParams(const aDatabase: string; const aUsername: string = ''; const aPassword: string = ''; const aLockingMode: TSQLiteLockingMode = mLockingExclusive; aEncrypt: TSQLiteEncryptMode = EncryptNone): iSQLiteParams; implementation type iBaseFiredacParams = iBaseFDParams<TBaseFiredacDriver>; TBaseConnectionParams = class(TInterfacedObject, iBaseFiredacParams) strict private protected function Pooled(aValue: Boolean): iBaseFiredacParams; overload; virtual; function Database(aValue: string): iBaseFiredacParams; overload; virtual; function Username(aValue: string): iBaseFiredacParams; overload; virtual; function Password(aValue: string): iBaseFiredacParams; overload; virtual; function Pooled: Boolean; overload; virtual; function Database: string; overload; virtual; function UserName: string; overload; virtual; function Password: string; overload; virtual; function Params: iBaseFiredacParams; virtual; procedure ValidateParams; virtual; abstract; end; TSqliteParams = class(TBaseConnectionParams, iSQLiteParams) public constructor Create (const aDatabase: string; const aUsername: string = ''; const aPassword: string = ''; const aLockingMode: TSQLiteLockingMode = mLockingExclusive; aEncrypt: TSQLiteEncryptMode = EncryptNone); procedure ValidateParams; override; function LockingMode(aValue: TSQLiteLockingMode): iBaseFDParams<TSQLiteDriver>; overload; virtual; function Encrypt(aValue: TSQLiteEncryptMode): iBaseFDParams<TSQLiteDriver>; overload; virtual; function LockingMode: TSQLiteLockingMode; overload; virtual; function Encrypt: TSQLiteEncryptMode; overload; virtual; end; function GetDefault_SqliteParams(const aDatabase: string; const aUsername: string = ''; const aPassword: string = ''; const aLockingMode: TSQLiteLockingMode = mLockingExclusive; aEncrypt: TSQLiteEncryptMode = EncryptNone): iSQLiteParams; begin Result := TSqliteParams.Create(aDatabase, aUsername,aPassword,aLockingMode, aEncrypt) as iSQLiteParams; end; end. TSqliteParams act as TTestFoo and TBaseConnectionParams as TBaseFoo- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
I am looking for a good software design solution that helps me avoid repeatedly implementing methods from TBaseFoo. Logically, by adding iTestFoo as an ancestor to TTestFoo, I am always forced to implement the methods of iBaseFoo, which come from iTestFoo. I want to avoid re-implementation of these methods. I tried marking the methods of TBaseFoo as virtual, but it didn’t help.- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
inheritance Ensuring Consistent Base Interface Implementation in Delphi Class Hierarchy
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
i search a workaround or a pure solution that let me avoid re-implementation of iBaseFoo methods since TBaseFoo Already there- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
ifthen strange return value !
bravesofts posted a topic in Algorithms, Data Structures and Class Design
why this IfThen inline function gives me Object is Allocated in memory !! --- type TMainView = class(TForm) Label1: TLabel; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var MainView: TMainView; implementation type TMyClass = class private // fValue: string; class var ClassValue: string; function GetValue: string; procedure SetValue(const aValue: string); public property Value: string Read GetValue write SetValue; end; { TMyClass } function TMyClass.GetValue: string; begin Result := ClassValue; end; procedure TMyClass.SetValue(const aValue: string); begin ClassValue := aValue; end; { TMainView } function IsAllocated(aObj: TMyClass): Boolean; begin Result := Assigned(aObj); case Result of True: aObj.Value := 'the OBJECT Is Allocated ..'; False: aObj.Value := 'Not Allocated Yet !!'; end; end; procedure TMainView.FormCreate(Sender: TObject); var LObj: TMyClass; begin // LObj := nil; // LObj := TMyClass.Create; Label1.Caption := IfThen(IsAllocated(LObj), LObj.Value, LObj.Value); end; link to github test project here -
ifthen strange return value !
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
Did the tone of this conversation lean towards mockery or belittling the person asking the question, or am I mistaken? -- In any case, thank you for the information. -
ifthen strange return value !
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
i agree with you @Rollo62 on this term, we should be the first to ask a good questions to get a good answers with best accuracy of the truth .. By the way, the answer from ChatGPT above would have been impossible without the question being, in reality, the answer from the highly respected and dear-to-my-heart @Dalija Prasnikar. If you take a closer look at what ChatGPT provided above, you’ll notice that it did a wonderful job of summarize, re-format and complete ., and beautifully elaborating on the esteemed professor Dalija Prasnikar's response.. The above post from ChatGPT 4.o is the best proof of what you say. --- finally , I want to thank you all once again for your amazing and enthusiastic contributions. Your accuracy in providing information has really helped me understand and sum up a journey that many people might still be struggling with. -
ifthen strange return value !
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
i ask GPT for a good Example and gives me this: procedure TMainView.Btn_1Click(Sender: TObject); var LObj: TMyClass; // Declare a local variable of reference type begin // At this point, LObj is just a pointer, and it hasn't been assigned to any object yet. ShowMessage(IntToStr(Integer(LObj))); // This may show some random (garbage) value LObj := TMyClass.Create; // Now, LObj points to a new instance of TMyClass allocated on the heap. ShowMessage(IntToStr(Integer(LObj))); // This will show the actual memory address of the object instance // When you’re done, free the object to avoid memory leaks. LObj.Free; end; Explanation LObj Declaration: LObj is declared as a variable of type TMyClass. This is a reference type, which means LObj is just a pointer (an address) that will eventually point to an object instance. Memory Allocation: LObj itself is a local variable, so it is allocated on the stack. However, the object instance that LObj will point to is allocated on the heap when you create it using TMyClass.Create. Garbage Value: When LObj is declared, it hasn't been initialized to point to anything. The memory allocated on the stack for LObj might contain whatever data was there before, which is why ShowMessage(IntToStr(Integer(LObj))) might display a random (garbage) value. This is because stack memory isn't automatically cleared. Object Creation: When you create a new instance of TMyClass with LObj := TMyClass.Create;, the memory for this instance is allocated on the heap. LObj now holds the memory address of this instance. Managed Types: Only managed types (e.g., strings, dynamic arrays, interfaces) are automatically initialized to nil or equivalent values when declared. Since LObj is not a managed type, it can hold any value until you explicitly initialize it by creating an object. Key Takeaways Uninitialized Pointers: If you don't initialize a reference type variable (like LObj), it might contain a garbage value that points to an undefined memory location. Memory Allocation: Local variables are allocated on the stack, but the actual object instances they point to are allocated on the heap. Automatic Initialization: Only managed types are automatically initialized to nil or similar default values when declared. This example illustrates the importance of initializing your reference variables to nil or creating an object before using them to avoid unexpected behavior. ---- I have a much clearer understanding of the entire process now. Thank you, everyone! -
ifthen strange return value !
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
So, the heap might contain some garbage data, and when we declare a variable, the pointer may refer to something that isn’t related to our program at all. Does this happen only in Windows? -
ifthen strange return value !
bravesofts replied to bravesofts's topic in Algorithms, Data Structures and Class Design
Do random values only occur for local variables? Why does uninitialized memory sometimes contain garbage values, especially when an object hasn't been allocated yet? LObj is just a variable that will reference the object once TMyClass creates it. Does TMyClass automatically assign anything to LObj just by declaring it like this? var LObj: TMyClass; -
the Real Purpose of using Reintroduce
bravesofts posted a topic in Algorithms, Data Structures and Class Design
the Purpose of reintroduce is to make a second introduce for same method from base class (not marked as virtual or dynamic) with overload arguments in Drived Class whith inherited ofcourse .. reintroduce let us add inherited in implementation of that overload method that reintroduced in Derrived Class ex: type TBaseClass = class public constructor Create; // no virtual or dynamic end; TDerivedClass = class(TBaseClass) public // constructor Create; overload// introduced as overload but no arguments there !! constructor Create(aArg:T); reintroduce; overload; end; implementation { TBaseClass } constructor TBaseClass.Create; begin // for example No code here !! end; { TDerivedClass } constructor TDerivedClass.Create; begin inherited Create; // reintroduce let us make inherited here //since base method is not marked as virtual or dynamic .. MyCode; // our method here will implement both (the inherited + MyCode) // but since the inherited is empty : the reintroduce here is Totally useless !! // the aim of reintroduce is to let us Merge the old method from base to reintroduce it // as a new method in derived class using directive [inherited] // does the overload necessary ? // if there is no necessary to add new arguments you can add just reintroduce to use // the inherited directive there .. // Is inherited mandatory when using reintroduce ? // a reintroduce without inherited is totally nosense !! end; finally : reintroduce is used especially for two Reasons: make inherited + overload with new parameters for same base method in Drived class make just inherited without overload it with new parameters Q1)does reintroduce work also with base methods marked as virtual or dynamic ? A1) do you heard about override ? Q2) but if i need to introduce it with my custom parameters ? A2) if that case ofcourse you need reintroduce; with overload; Q3) is overload mandatory ? A3) since reintroduce her second work is to hide any warnning compiler i can say yes the overload is a mandatory logically .. ----- if i'm wrong plz tell me (Many thanks in Advance)