Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


DavidRM last won the day on February 11

DavidRM had the most liked content!

About DavidRM

  • Rank

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    Tulsa, OK

Recent Profile Visitors

183 profile views
  1. Thanks, but I don't really understand your choices in that code. I already have a workaround. I want the compiler fixed. -David
  2. This... procedure PXTeamCreate(aTeam: TTeamStruct; aCallback: TPXMessageCallback); begin var aData: Variant := new JObject; aData.team := aTeam.Save; PXSend(PXM_TEAMCREATE, aData, aCallback); end; Compiles to this: function PXTeamCreate(aTeam$4, aCallback$4) { var aData$5; aData$5 = {}; aData$5.team = {}; PXSend(122,aData$5,aCallback$4); }; All I can figure is that TTeamStruct.Save returns a *record* type, and somehow the poor result is being scoped out of existence before it even gets a chance. function TTeamStruct.Save: TTeamXfer; begin Result.TeamID := TeamID; Result.Name := Name; Result.Desc := Desc; Result.Web := Web; Result.Bonus := Bonus; Result.Shots := Shots; Result.Splats := Splats; Result.BonusCurrent := BonusCurrent; Result.ShotsCurrent := ShotsCurrent; Result.SplatsCurrent := SplatsCurrent; end; TTeamXfer = record TeamID: integer; external 'teamID'; Name: string; external 'name'; Desc: string; external 'desc'; Web: string; external 'web'; Bonus: integer; external 'bonus'; Shots: integer; external 'shots'; Splats: integer; external 'splats'; BonusCurrent: integer; external 'bonusCurrent'; ShotsCurrent: integer; external 'shotsCurrent'; SplatsCurrent: integer; external 'splatsCurrent'; end; Here's my current workaround: procedure PXTeamCreate(aTeam: TTeamStruct; aCallback: TPXMessageCallback); begin var aData: Variant := new JObject; var aTeamXfer := aTeam.Save; asm (@aData).team = @aTeamXfer; end; PXSend(PXM_TEAMCREATE, aData, aCallback); end;
  3. That did what I wanted. Thanks! -David
  4. That can work in simple projects, but as soon as you have to 2 record types with the same field name, the Object Pascal field name no longer matches the JSON field name. For example, "CategoryID" would be emitted as "CategoryID" (a perfect match) for one record type, but "CategoryID$1" (not so perfect) for another. -David
  5. I find myself doing this a lot: type TTeamStruct = class (TObject) TeamID: integer; Name, Desc, Web: string; Bonus, Shots, Splats, BonusCurrent, ShotsCurrent, SplatsCurrent: integer; procedure FromJSON(json: string); function ToJSON: string; procedure FromJObject(aObj: Variant); function AsJObject: Variant; end; procedure TTeamStruct.FromJSON(json: string); var aObj: Variant; begin asm @aObj = JSON.parse(@json); end; FromJObject(aObj); end; function TTeamStruct.ToJSON: string; var aObj: Variant; begin aObj := Self.AsJObject; asm @Result = JSON.stringify(@aObj); end; end; procedure TTeamStruct.FromJObject(aObj: Variant); begin TeamID := aObj.teamID; Name := aObj.name; Desc := aObj.desc; Web := aObj.web; Bonus := aObj.bonus; Shots := aObj.shots; Splats := aObj.splats; BonusCurrent := aObj.bonusCurrent; ShotsCurrent := aObj.shotsCurrent; SplatsCurrent := aObj.splatsCurrent; end; function TTeamStruct.AsJObject: Variant; begin Result := new JObject; Result.teamID := TeamID; Result.name := Name; Result.desc := Desc; Result.web := Web; Result.bonus := Bonus; Result.shots := Shots; Result.splats := Splats; Result.bonusCurrent := BonusCurrent; Result.shotsCurrent := ShotsCurrent; Result.splatsCurrent := SplatsCurrent; end; I do this to simplify the Json storage, especially for transmitting between client and server. If I don't do this, I end up with a lot of SMS "artifacts" in my Json because SMS makes sure all field names are unique (which I totally get). Is there some trick I can use to *not* have to write this code for pretty much every object flying back and forth? Thanks! -David
  6. DavidRM

    lamda doesn't highlight its end

    Clicking on keyword "lambda" doesn't highlight its "end". In the same vein, cilcking on "end" for a lambda, highlights a totally wrong "begin". -David
  7. DavidRM

    Declaring Record Type Constants

    I want *less* stuff to type, not more. BUt thanks for the options. 😃 -David
  8. DavidRM

    Declaring Record Type Constants

    Here's my solution: type TMySqlCreateTable = class TableName: string; CreateFunc: function: JPromise; constructor Create(const aTableName: string; aCreateFunc: function: JPromise); begin TableName := aTableName; CreateFunc := aCreateFunc; end; end; var _TableList: array of TMySqlCreateTable; procedure CreateTableList; begin _TableList.Clear; _TableList.Add(TMySqlCreateTable.Create('Server', @CreateServerTable)); _TableList.Add(TMySqlCreateTable.Create('GameData', @CreateGameDataTable)); _TableList.Add(TMySqlCreateTable.Create('Team', @CreateTeamTable)); _TableList.Add(TMySqlCreateTable.Create('Player', @CreatePlayerTable)); _TableList.Add(TMySqlCreateTable.Create('PlayerBody', @CreatePlayerBodyTable)); _TableList.Add(TMySqlCreateTable.Create('PlayerLocker', @CreatePlayerLockerTable)); _TableList.Add(TMySqlCreateTable.Create('PlayerAliases', @CreatePlayerAliasesTable)); _TableList.Add(TMySqlCreateTable.Create('PlayerIgnores', @CreatePlayerIgnoresTable)); _TableList.Add(TMySqlCreateTable.Create('PlayerButtons', @CreatePlayerButtonsTable)); _TableList.Add(TMySqlCreateTable.Create('PlayerNotes', @CreatePlayerNotesTable)); _TableList.Add(TMySqlCreateTable.Create('PlayerUIOptions', @CreatePlayerUIOptionsTable)); _TableList.Add(TMySqlCreateTable.Create('Purchases', @CreatePurchasesTable)); _TableList.Add(TMySqlCreateTable.Create('Rankings', @CreateRankingsTable)); end; Turn it into a class, declare an array variable, write a function to fill it up. I would rather just declare it as a constant. -David
  9. DavidRM

    Declaring Record Type Constants

    Why won't this work? type TMySqlCreateTable = record TableName: string; CreateFunc: function: JPromise; end; const _TableList: array of TMySqlCreateTable = [ (TableName: 'Server'; CreateFunc: @CreateServer) ]; This would be valid in Delphi, and the SMS parser even recognizes the validity of "(TableName: 'Server'; CreateFunc: @CreateServer)", but gives the error "constant expression expected". But it *IS* a constant expression. Thanks. -David
  10. DavidRM

    Enable User Selection of Text

    @jarto That did it, yup. Thanks! And, yes, I had to use tmsText. Also, I was able to get the span to work by doing this: InnerHTML := Format('<span style="color:%s;user-select:text;-moz-user-select:text;-webkit-user-select:text;-ms-user-select:text;-khtml-user-select:text"><b>%s</b>: %s</span>', [ColorToWebStr(FChatColor), TString.EncodeTags(FChatHeader), TString.EncodeTags(FChatText)]); Not sure why the <span> didn't just inherit the item's user-select, though. Thanks! -David
  11. DavidRM

    Enable User Selection of Text

    THis is what I have: type TPBTScrollItem = class(TW3CustomControl) protected FItemText: string; procedure InitializeItem; virtual; procedure SetItemText(aValue: string); public function CreationFlags: TW3CreationFlags; override; procedure UpdateDisplay; virtual; property ItemText: string read FItemText write SetItemText; end; // TPBTScrollItem procedure TPBTScrollItem.InitializeItem; begin SetContentSelectionMode(tsmAuto); end; procedure TPBTScrollItem.SetItemText(aValue: string); begin if aValue <> FItemText then begin FItemText := aValue; UpdateDisplay; end; end; function TPBTScrollItem.CreationFlags: TW3CreationFlags; begin inherited; Include(Result, cfAllowSelection); end; procedure TPBTScrollItem.UpdateDisplay; begin InnerHTML := Format('<span>%s</span>', [TString.EncodeTags(FItemText)]); end; But the user can never actually click-and-drag to select the content. Why? And: How do I get around whatever silly reason is the "Why?" Thanks! -David
  12. DavidRM

    NodeJS file utils and native app

    Here's my example: Files := TW3NodeStorageDevice.Create(nil); Files.Mount(nil, procedure (Sender: TW3StorageDevice; Success: boolean) begin if Success then Writeln(PBNRS_FILE_SYSTEM_MOUNTED) else Writeln(Format(PBNRS_ERROR_MOUNTING_FILE_SYSTEM, [Files.LastError])); end ); And reading a file: Files.Load(PBNConfig.HelpFile, procedure (Sender: TW3StorageDevice; Filename: string; Data: TStream; Success: boolean) begin if Success then begin ... end else ... end
  13. DavidRM

    Node.JS Deprecation Warning

    @IElite Yes, I did. But I don't use that directly. I'm guessing it's in the SMS RTL for NodeJS, so I wanted to pass it along. -David
  14. DavidRM

    Node.JS Deprecation Warning

    I get this notification from Node.JS (10.15.0) sometimes: [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. -David
  15. DavidRM

    My SMS Project: Paintball Net Revival

    I wondered if any old players would find this page. 😃 Testing is now underway. When I have a few more the bugs shaken out [*], I'll post the link here. -David [*] You post 10's of thousands of lines of ANSI C to Object Pascal and see if you don't have some typos...