Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.pascal.delphi.misc > #732
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | "P E Schoen" <paul@pstech-inc.com> |
| Newsgroups | comp.lang.pascal.delphi.misc |
| Subject | Strings and PChar (D4 Pro) |
| Date | Sat, 27 Aug 2016 05:39:10 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 2 |
| Message-ID | <nprn44$mvb$1@dont-email.me> (permalink) |
| Mime-Version | 1.0 |
| Content-Type | text/plain; format=flowed; charset="iso-8859-1"; reply-type=original |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Sat, 27 Aug 2016 09:39:16 -0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="b1af19846bb81aaa3b3db89d0d6b1b2f"; logging-data="23531"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/w9seSxkKqo2PkZkZZj7OabQ+B6z8HQ2c=" |
| X-MimeOLE | Produced By Microsoft MimeOLE V16.4.3564.1216 |
| X-Newsreader | Microsoft Windows Live Mail 16.4.3564.1216 |
| Importance | Normal |
| Cancel-Lock | sha1:eisTJjdO6w90jD84tG9VfIrarBc= |
| X-Priority | 3 |
| X-MSMail-Priority | Normal |
| Xref | csiph.com comp.lang.pascal.delphi.misc:732 |
Show key headers only | View raw
This is probably a very basic question, but I may have been improperly
casting a string to PChar in some cases. For instance, I got the following
code to work as shown:
====================================================
procedure TfmOrtDatabase.btBackupClick(Sender: TObject);
var udfn: OrtData.TUserDataFile;
S, dbFileName, saveFileName, dirName: String;
// currDir: String;
currDir: array[0..50] of Char;
begin
if Application.MessageBox( 'Backup Database Files?',
'Backup', MB_YESNO ) = ID_YES then begin //1
// currDir := '01234567890123456789012345678901234567890123456789';
// SetLength(currDir,50);
GetCurrentDirectory(sizeof(currDir)+1, @currDir);
dirName := GetSystemFolder(CSIDL_PERSONAL);
dirName := dirName + '\Ortmaster';
SelectDirectory(dirName, [sdAllowCreate,sdPerformCreate], 0);
// SelectDirectory('Select Directory', dirName, dirName);
S := FormatDateTime('yyyymmdd', Now);
fmDBSaveDialog.InitialDir := dirName;
for udfn := udfCust to udfTypes do begin //2
dbFileName := ProgramDataFolder + '\' +
OrtData.UserFileName[udfn]+'.dbf';
fmDBSaveDialog.FileName := OrtData.UserFileName[udfn]+'.dbf';
if not (fmDBSaveDialog.Execute) then exit;
if (FileExists(dbFileName)) then begin //3
saveFileName := fmDBSaveDialog.FileName + '-' + S;
if not( CopyFile( pChar(dbFileName), PChar(saveFileName), FALSE ) )
then
MessageDlg('File Copy Error', mtInformation, [mbOK], 0);;
end; //-3
end; //-2
fmDBSaveDialog.InitialDir := dirName;
dbFileName := 'Ortmaster' + '.rcf';
fmDBSaveDialog.FileName := dbFileName;
dbFileName := ProgramDataFolder + '\Ortmaster' + '.rcf';
if not (fmDBSaveDialog.Execute) then exit;
if (FileExists(dbFileName)) then begin //2
saveFileName := fmDBSaveDialog.FileName + '-' + S;
if not( CopyFile( pChar(dbFileName), pChar(saveFileName), FALSE ) )
then
MessageDlg('File Copy Error', mtInformation, [mbOK], 0);;
end; //-2
SetCurrentDirectory(currDir);
end; //-1
end;
=========================================================
If I used an uninitialized string, the GetCurrentDirectory() function
failed, even when I initialized the string to a constant as shown. It's
rather late, and maybe my brain is fogged, but it seems like there should be
a better way to do this. It would be nice if there were a function like
GetSystemFolder() that returns a string.
BTW, the SelectDirectory() function seems to be what I was searching for in
a post from 7/20/15.
Also, I'm not sure why the current directory got changed by the function.
Thanks,
Paul
Back to comp.lang.pascal.delphi.misc | Previous | Next — Next in thread | Find similar
Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 05:39 -0400
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:03 -0400
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:28 -0400
Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 18:00 +0700
Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 13:41 +0200
Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 17:05 +0700
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:15 -0400
Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 18:09 +0700
Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 13:12 +0200
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 18:59 -0400
Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 12:50 +0200
csiph-web