Jump to content

Search the Community

Showing results for tags 'function'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Delphi Questions and Answers
    • Algorithms, Data Structures and Class Design
    • VCL
    • FMX
    • RTL and Delphi Object Pascal
    • Databases
    • Network, Cloud and Web
    • Windows API
    • Cross-platform
    • Delphi IDE and APIs
    • General Help
    • Delphi Third-Party
  • C++Builder Questions and Answers
    • General Help
  • General Discussions
    • Embarcadero Lounge
    • Tips / Blogs / Tutorials / Videos
    • Job Opportunities / Coder for Hire
    • I made this
  • Software Development
    • Project Planning and -Management
    • Software Testing and Quality Assurance
  • Community
    • Community Management

Calendars

  • Community Calendar

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Delphi-Version

Found 3 results

  1. Specs: Win7, Delphi 11.2, VCL I wrote some functions to convert string to byte and byte to string. These functions work. For testing, I added several tbuttons and a memo on the form and began testing my ideas shown below. function str2byte(str: string): TBytes; begin setlength(str,length(str)); result := TEncoding.utf8.getbytes(str); end; function byte2str(byt: TBytes): string; begin result := TEncoding.ascii.getstring(byt); end; usage: procedure TForm1.Button1Click(Sender: TObject); var strs: string; bytes: TBytes; begin bytes := str2byte('ABC'); // string strs := byte2str(bytes); // bytes memo1.Lines.Add(byte2str(bytes)); // show it strs := byte2str([68,69,70]); // bytes bytes := str2byte(strs); // string memo1.Lines.Add(byte2str(bytes)); // show it end; Now, I'd like to extend that to include an additional parameter to the encoding format (ansi, ascii, utf-16-big-endian unicode, utf-16 unicode, utf-7 and utf-8) as found here: https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.SysUtils.TEncoding (And then later, possibly extend upon it by building a class component of it (and other library functions/procedures that I build)). The issue I am having now is how to give the parameters their name. I do not know if there are already built-in types for these and don't want to cause issues later on. But so far, I thought about using these: (_ansi, _ascii, _utf7, _utf8, _utf16be and _utf16u). Or, maybe create an enumerated list, i.e., type TMyEncoding = (_ansi, _ascii, _utf7, _utf8, _utf16be, _utf16u); And rewriting the above output snippet: type TMyEncoding = (_ansi, _ascii, _utf7, _utf8, _utf16be, _utf16u); function _byte2str(byt: TBytes; enc: TMyEncoding): string; begin case integer(enc) of 0: result := TEncoding.ascii.getstring(byt); 1: result := TEncoding.ansi.getstring(byt); 2: result := TEncoding.utf7.getstring(byt); 3: result := TEncoding.utf8.getstring(byt); // ... end; end; procedure TForm1.Button4Click(Sender: TObject); var strs: string; bytes: TBytes; begin bytes := str2byte('_ansi'); // string strs := _byte2str(bytes,_ansi); // bytes memo1.Lines.Add(_byte2str(bytes,_ansi)); // show it // strs := byte2str([68,69,70]); // bytes // bytes := str2byte(strs); // string // memo1.Lines.Add(byte2str(bytes)); // show it end; So I am looking for some advice/suggestions on how to implement the names for each of the encodings that will not interfer with Delphi's built-in names. TIA.
  2. Hi, I'll try auto-increment value in mongodb although, basically not support autoincrement field value in mongodb. example) https://www.tutorialspoint.com/mongodb/mongodb_autoincrement_sequence.htm that is working in cli. but, i want do it firedac component. and i can't find any support execute script procedures. can i use that script in firedac? or other way??? or impossible? p.s : sorry for my poor english.
  3. bazzer747

    DecodeDate Issue

    Hi, I have a project where I need to get the value of a year in a field so I use DecodeDate( dtDate, Year, Month, Day); where dtDate is a TDateTime variable, Year, Month, Day are Word variables. When I run the code I get an error - 'Constant or type identifier expected'. I've downloaded the example Embarcadero have for using DecodeDate: procedure TfAccounts.Button1Click(Sender: TObject); var Present: TDateTime; Year, Month, Day: Word; begin Present:= Now; System.SysUtils.DecodeDate(Present, Year, Month, Day); Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month ' + IntToStr(Month) + ' of Year ' + IntToStr(Year); end; .. and get this same error. The 'Word' is red-underlines as the error. I have System.SysUtils in the Uses clause: uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, ... etc I have used this same code in a different project and it works with no error. I can't think of why it isn't working in this particular project. Unless some other unit in the Uses clause is causing a problem, although SysUtils comes almost first. Any thoughts would be welcomed.
×