Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 04/19/20 in all areas

  1. Dave Nottage

    Delphi fmx comes standard in iOS font

    It also works for me just by having the Font.Family property in TextSettings set to the correct value (i.e. Anton) at design time. Using the button and code was just to demonstrate that there's a very obvious change in the font. I suspect there's something else wrong with your project, which is why I asked to post a test case.
  2. I also usually use class helpers, that implement the new methods for the old Delphi versions. Not the other way around!
  3. I usually write class helper for this. They can easily be removed when older versions are dropped.
  4. Dave Nottage

    Delphi fmx comes standard in iOS font

    I'm using Delphi 10.3.3, the latest released version of Xcode (11.4), building against the latest iOS SDK (13.4) and it works on my iPhone X which has iOS 13.4. I've attached my test project (which uses the Anton font, from here: https://fonts.google.com/specimen/Anton). Perhaps if you have a test project, you could attach it so it might be discovered what is going wrong. CustomFontDemo.zip
  5. I would rewrite that to something more like this instead. Don't duplicate code that doesn't need to be duplicated: var LCount: Integer; LCount := o.{$IFDEF JSONOBJ_HAS_COUNT}Count{$ELSE}Size{$ENDIF}; if LCount <> 3 then raise Exception.CreateFmt(_('Parsing error on JSON answer: Root object size is %d not 3.'), [LCount]); I would just write a class helper or separate function, and IFDEF the code inside of it. Class helpers were first introduced in Delphi 2005, but were buggy and not officially supported until Delphi 2006. JSON was first introduced in Delphi 2010.
  6. To use a TFileStream just to check if the file is in use, you need to use fmOpenRead instead of fmCreate, and you definitely need to use fmShareExclusive instead of fmShareDenyNone, and note that the file could fail to open for any number of reasons, not all of which are related to the file being in use, so you have to check for that, eg: function FileReallyIsInUse(fName: string): boolean; begin Result := False; try TFileStream.Create(fName, fmOpenRead or fmShareExclusive).Free; except on E: EFOpenError do Result := GetLastError() in [ERROR_SHARING_VIOLATION, ERROR_LOCK_VIOLATION]; end; end; However, the exception doesn't carry the error code, and using GetLastError() after the exception is raised does not guarantee the original error code is preserved. You are better off simply calling the Win32 CreateFile() function directly instead (which avoids the need to allocate an object in memory, or invoke the overhead of exception handling): function FileReallyIsInUse(fName: string): boolean; var hFile: THandle; begin hFile := CreateFile(PChar(fName), GENERIC_READ, 0, nil, OPEN_EXISTING, 0, 0); if hFile <> INVALID_HANDLE_VALUE then begin CloseHandle(hFile); Result := False; end else Result := GetLastError() in [ERROR_SHARING_VIOLATION, ERROR_LOCK_VIOLATION]; end; Or, the RTL's FileOpen() function: function FileReallyIsInUse(fName: string): boolean; var hFile: THandle; begin hFile := FileOpen(fName, fmOpenRead or fmShareExclusive); if hFile <> INVALID_HANDLE_VALUE then begin FileClose(hFile); Result := False; end else Result := GetLastError() in [ERROR_SHARING_VIOLATION, ERROR_LOCK_VIOLATION]; end;
×