Thursday, March 19, 2020

Create a Database Using Delphis File Of Typed Files

Create a Database Using Delphi's File Of Typed Files Simply put a file is a binary sequence of some type. In Delphi, there are three classes of file: typed, text, and untyped. Typed files are files that contain data of a particular type, such as Double, Integer or previously defined custom Record type. Text files contain readable ASCII characters. Untyped files are used when we want to impose the least possible structure on a file. Typed Files While text files consist of lines terminated with a CR/LF (#13#10) combination, typed files consist of data taken from a particular type of data structure. For example, the following declaration creates a record type called TMember and an array of TMember record variables. type   Ã‚  TMember record   Ã‚  Ã‚  Ã‚  Name : string[50];  Ã‚  Ã‚  Ã‚  eMail : string[30];  Ã‚  Ã‚  Ã‚  Posts : LongInt;  Ã‚  end;  var Members : array[1..50] of TMember; Before we can write the information to the disk, we have to declare a variable of a file type. The following line of code declares an F file variable. var F : file of TMember; Note: To create a typed file in Delphi, we use the following syntax: var SomeTypedFile : file of SomeType The base type (SomeType) for a file can be a scalar type (like Double), an array type or record type. It should not be a long string, dynamic array, class, object or a pointer. To start working with files from Delphi, we have to link a file on a disk to a file variable in our program. To create this link, we must use AssignFile procedure to associate a file on a disk with a file variable. AssignFile(F, Members.dat) Once the association with an external file is established, the file variable F must be opened to prepare it for reading and writing. We call Reset procedure to open an existing file or Rewrite to create a new file. When a program completes processing a file, the file must be closed using the CloseFile procedure. After a file is closed, its associated external file is updated. The file variable can then be associated with another external file. In general, we should always use exception handling; many errors may arise when working with files. For example: if we call CloseFile for a file that is already closed Delphi reports an I/O error. On the other hand, if we try to close a file but have not yet called AssignFile, the results are unpredictable. Write to a File Suppose we have filled an array of Delphi members with their names, e-mails, and number of posts and we want to store this information in a file on the disk. The following piece of code will do the work: var   Ã‚  F : file of TMember;  Ã‚  i : integer;begin   AssignFile(F,members.dat) ;   Rewrite(F) ;   try   Ã‚  for j: 1 to 50 do   Ã‚  Ã‚  Write (F, Members[j]) ;   finally   Ã‚  CloseFile(F) ;   end;end; Read from a File To retrieve all the information from the members.dat file we would use the following code: var   Ã‚  Member: TMember   Ã‚  F : file of TMember;begin   AssignFile(F,members.dat) ;   Reset(F) ;   try   Ã‚  while not Eof(F) do begin   Ã‚  Ã‚  Read (F, Member) ;   Ã‚  Ã‚  {DoSomethingWithMember;}   Ã‚  end;  finally   Ã‚  CloseFile(F) ;   end;end; Note: Eof is the EndOfFile checking function. We use this function to make sure that we are not trying to read beyond the end of the file (beyond the last stored record). Seeking and Positioning Files are normally accessed sequentially. When a file is read using the standard procedure Read or written using the standard procedure Write, the current file position moves to the next numerically ordered file component (next record). Typed files can also be accessed randomly through the standard procedure Seek, which moves the current file position to a specified component. The FilePos and FileSize functions can be used to determine the current file position and the current file size. {go back to the beginning - the first record} Seek(F, 0) ; {go to the 5-th record} Seek(F, 5) ; {Jump to the end - after the last record} Seek(F, FileSize(F)) ; Change and Update Youve just learned how to write and read the entire array of members, but what if all you want to do is to seek to the 10th member and change the e-mail? The next procedure does exactly that: procedure ChangeEMail(const RecN : integer; const NewEMail : string) ;var DummyMember : TMember;begin   {assign, open, exception handling block}   Seek(F, RecN) ;   Read(F, DummyMember) ;   DummyMember.Email : NewEMail;   {read moves to the next record, we have to   go back to the original record, then write}   Seek(F, RecN) ;   Write(F, DummyMember) ;   {close file}end; Completing the Task Thats it- now you have all you need to accomplish your task. You can write members information to the disk, you can read it back, and you can even change some of the data (e-mail, for example) in the middle of the file. Whats important is that this file is not an ASCII file, this is how it looks in Notepad (only one record): .Delphi Guide g Ã’5 ·Ã‚ ¿Ãƒ ¬. 5. . B V.LÆ’ ,„ ¨.delphiaboutguide.comà .. à §.à §.à ¯..

Tuesday, March 3, 2020

How to Treat Complex Phrasal Adjectives

How to Treat Complex Phrasal Adjectives How to Treat Complex Phrasal Adjectives How to Treat Complex Phrasal Adjectives By Mark Nichol Numerous DailyWritingTips.com posts have addressed hyphenation of phrasal adjectives such as â€Å"long range† when they precede a noun, as in â€Å"long-range missile.† But what about when the phrasal adjective includes more than two words? As this post explains, it depends on the interrelationships of those words. The simplest multiword phrasal adjective to construct is one in which a phrase such as â€Å"all or nothing† modifies a noun- simply hyphenate the string of words: â€Å"all-or-nothing ultimatum.† This rule holds true no matter how long the string is, though at a certain point, the writer or editor may decide that it is of a cumbersome length, in which case omitting hyphens and enclosing the string in quotation marks to suggest that the phrasal adjective is spoken will render it more readable, or recasting the sentence may improve clarity. But what if two of the words are already an open or hyphenated compound- a standing phrase that appears in the dictionary as such- or is a proper noun? In either case, the solution is to replace the hyphens linking every word with an en dash (–) linking the compound to an additional word. (An en dash is a symbol usually seen in number ranges, as in â€Å"The room accommodates 25–50 people depending on seating arrangement† or â€Å"Jones lived 1911–1987.†) This usage is clear when employed with proper nouns, as in â€Å"San Francisco ­Ã¢â‚¬â€œbased company† (as opposed to the absurd alternative â€Å"San-Francisco-based company†), where based obviously relates to â€Å"San Francisco,† not just Francisco, but it is also used in such constructions as â€Å"open standards–based solutions,† where â€Å"open standards† is a well-known phrase. The risk in such usage is that readers will not recognize that the en dash is distinct from a hyphen and will (mis)understand the phrase to mean â€Å"standards-based solutions that are open.† This risk is exacerbated by the fact that the Associated Press Style Book, in its sometimes-misguided quest to simplify symbols, calls for a hyphen rather than an en dash in phrases like this, which could lead to such confusion. Another option is to use the hyphen-string approach in such phrases as â€Å"think-tank-inspired policies† (instead of â€Å"think tank–inspired policies†) or â€Å"soft-drink-soaked shirt† (rather than â€Å"soft drink–soaked shirt†), but better yet, try the more relaxed syntax presented, for example, in â€Å"policies inspired by think tanks† and â€Å"shirt soaked with a soft drink.† Want to improve your English in five minutes a day? Get a subscription and start receiving our writing tips and exercises daily! Keep learning! Browse the Grammar category, check our popular posts, or choose a related post below:7 Types of Narrative ConflictLoan, Lend, Loaned, LentDealing With A Character's Internal Thoughts