Autor Beitrag
dominikb
Hält's aus hier
Beiträge: 8

Win XP SP2
Borland Delphi Pascal 6
BeitragVerfasst: Fr 24.11.06 17:03 
Hallo zusammen,

habe folgende frage: Ich möchte mein Array immer in dem Verzeichnis speichern
von wo aus das Programm mit dem ich es speicher, gestartet wurde.
Ich kenn das nur so das man den vollständigen Pfad angeben muss bzw. auf ein SaveDialog verweißt.

Hier ist mein Quellcode:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
 
dosname:=savedialog1.filename;
    try
      assignfile(finfo,dosname);
      rewrite(finfo);
      for i:=1 to anzahl do
        write(finfo,songliste[i]); //finfo=record, songliste=array
        closefile(finfo);
    except
      on EInOutError do
      messagedlg('Ein Fehler ist aufgetreten :Dateiname:='+dosname,mterror,[mbok],0)




Kann mir da jm helfen???


Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Fr 24.11.2006 um 19:45
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 24.11.06 18:40 
Moin!

Schau dir mal Application.Exename an. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Manina
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 44

Win 7 Pro
RAD Studio 2010 Pro
BeitragVerfasst: Fr 24.11.06 19:36 
und dazu noch ExtractFilePath :wink:

_________________
Gates, oder Gates nicht ?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Fr 24.11.06 19:45 
Hallo!

Du solltest Dir außerdem überlegen, ob Du das wirklich möchtest. Denn unter Windows 2000/XP & Co. hat ein normaler Nutzer selten Schreibzugriff auf das Programmverzeichnis!

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
zongo-joe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 134

win xp prof
D3, D4, D7
BeitragVerfasst: So 26.11.06 00:03 
würd ich christian S voll zustimmen !
Die Speicherung in den Programmordner funzt überhaupt net gut !

Da würde ich eher EIGENE DATEIEN empfehlen.
Das und die übrigen Systemordner kriegst Du so raus: (ich hab mal 2 Funkionen reingepackt)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
USES shlobj
Var pidl: PItemIdList;

SHGetSpecialFolderLocation(Application.Handle, CSIDL_PERSONAL, pidl);  {Der Ordner Eigene Dateien}
 SHGetSpecialFolderLocation(Application.Handle, CSIDL_APPDATA, pidl);   {Der Ordner "Anwendungsdaten"}


CSIDL

CSIDL values provide a unique system-independent way to identify special folders used frequently by applications, but which may not have the same name or location on any given system. For example, the system folder may be "C:\Windows" on one system and "C:\Winnt" on another. These constants are defined in Shlobj.h and Shfolder.h.

Constants

    CSIDL_FLAG_CREATE (0x8000)
        Version 5.0. Combine this CSIDL with any of the following CSIDLs to force the creation of the associated folder. 

    CSIDL_ADMINTOOLS (0x0030)
        Version 5.0. The file system directory that is used to store administrative tools for an individual user. The Microsoft Management Console (MMC) will save customized consoles to this directory, and it will roam with the user.

    CSIDL_ALTSTARTUP (0x001d)
        The file system directory that corresponds to the user's nonlocalized Startup program group.

    CSIDL_APPDATA (0x001a)
        Version 4.71. The file system directory that serves as a common repository for application-specific data. A typical path is C:\Documents and Settings\username\Application Data. This CSIDL is supported by the redistributable Shfolder.dll for systems that do not have the Microsoft Internet Explorer 4.0 integrated Shell installed.

    CSIDL_BITBUCKET (0x000a)
        The virtual folder containing the objects in the user'
s Recycle Bin.

    CSIDL_CDBURN_AREA (0x003b)
        Version 6.0. The file system directory acting as a staging area for files waiting to be written to CD. A typical path is C:\Documents and Settings\username\Local Settings\Application Data\Microsoft\CD Burning.

    CSIDL_COMMON_ADMINTOOLS (0x002f)
        Version 5.0. The file system directory containing administrative tools for all users of the computer.

    CSIDL_COMMON_ALTSTARTUP (0x001e)
        The file system directory that corresponds to the nonlocalized Startup program group for all users. Valid only for Microsoft Windows NT systems.

    CSIDL_COMMON_APPDATA (0x0023)
        Version 5.0. The file system directory containing application data for all users. A typical path is C:\Documents and Settings\All Users\Application Data.

    CSIDL_COMMON_DESKTOPDIRECTORY (0x0019)
        The file system directory that contains files and folders that appear on the desktop for all users. A typical path is C:\Documents and Settings\All Users\Desktop. Valid only for Windows NT systems.

    CSIDL_COMMON_DOCUMENTS (0x002e)
        The file system directory that contains documents that are common to all users. A typical paths is C:\Documents and Settings\All Users\Documents. Valid for Windows NT systems and Microsoft Windows 95 and Windows 98 systems with Shfolder.dll installed.

    CSIDL_COMMON_FAVORITES (0x001f)
        The file system directory that serves as a common repository for favorite items common to all users. Valid only for Windows NT systems.

    CSIDL_COMMON_MUSIC (0x0035)
        Version 6.0. The file system directory that serves as a repository for music files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Music.

    CSIDL_COMMON_PICTURES (0x0036)
        Version 6.0. The file system directory that serves as a repository for image files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Pictures.

    CSIDL_COMMON_PROGRAMS (0x0017)
        The file system directory that contains the directories for the common program groups that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs. Valid only for Windows NT systems.

    CSIDL_COMMON_STARTMENU (0x0016)
        The file system directory that contains the programs and folders that appear on the Start menu for all users. A typical path is C:\Documents and Settings\All Users\Start Menu. Valid only for Windows NT systems.

    CSIDL_COMMON_STARTUP (0x0018)
        The file system directory that contains the programs that appear in the Startup folder for all users. A typical path is C:\Documents and Settings\All Users\Start Menu\Programs\Startup. Valid only for Windows NT systems.

    CSIDL_COMMON_TEMPLATES (0x002d)
        The file system directory that contains the templates that are available to all users. A typical path is C:\Documents and Settings\All Users\Templates. Valid only for Windows NT systems.

    CSIDL_COMMON_VIDEO (0x0037)
        Version 6.0. The file system directory that serves as a repository for video files common to all users. A typical path is C:\Documents and Settings\All Users\Documents\My Videos.

    CSIDL_COMPUTERSNEARME (0x003d)
        The folder representing other machines in your workgroup.

    CSIDL_CONNECTIONS (0x0031)
        The virtual folder representing Network Connections, containing network and dial-up connections. 

    CSIDL_CONTROLS (0x0003)
        The virtual folder containing icons for the Control Panel applications.

    CSIDL_COOKIES (0x0021)
        The file system directory that serves as a common repository for Internet cookies. A typical path is C:\Documents and Settings\username\Cookies.

    CSIDL_DESKTOP (0x0000)
        The virtual folder representing the Windows desktop, the root of the namespace.

    CSIDL_DESKTOPDIRECTORY (0x0010)
        The file system directory used to physically store file objects on the desktop (not to be confused with the desktop folder itself). A typical path is C:\Documents and Settings\username\Desktop.

    CSIDL_DRIVES (0x0011)
        The virtual folder representing My Computer, containing everything on the local computer: storage devices, printers, and Control Panel. The folder may also contain mapped network drives.

    CSIDL_FAVORITES (0x0006)
        The file system directory that serves as a common repository for the user's favorite items. A typical path is C:\Documents and Settings\username\Favorites.

    CSIDL_FONTS (0x0014)
        A virtual folder containing fonts. A typical path is C:\Windows\Fonts.

    CSIDL_HISTORY (0x0022)
        The file system directory that serves as a common repository for Internet history items.

    CSIDL_INTERNET (0x0001)
        A virtual folder representing the Internet.

    CSIDL_INTERNET_CACHE (0x0020)
        Version 4.72. The file system directory that serves as a common repository for temporary Internet files. A typical path is C:\Documents and Settings\username\Local Settings\Temporary Internet Files.

    CSIDL_LOCAL_APPDATA (0x001c)
        Version 5.0. The file system directory that serves as a data repository for local (nonroaming) applications. A typical path is C:\Documents and Settings\username\Local Settings\Application Data.

    CSIDL_MYDOCUMENTS (0x000c)
        Version 6.0. The virtual folder representing the My Documents desktop item.

    CSIDL_MYMUSIC (0x000d)
        The file system directory that serves as a common repository for music files. A typical path is C:\Documents and Settings\User\My Documents\My Music.

    CSIDL_MYPICTURES (0x0027)
        Version 5.0. The file system directory that serves as a common repository for image files. A typical path is C:\Documents and Settings\username\My Documents\My Pictures.

    CSIDL_MYVIDEO (0x000e)
        Version 6.0. The file system directory that serves as a common repository for video files. A typical path is C:\Documents and Settings\username\My Documents\My Videos.

    CSIDL_NETHOOD (0x0013)
        A file system directory containing the link objects that may exist in the My Network Places virtual folder. It is not the same as CSIDL_NETWORK, which represents the network namespace root. A typical path is C:\Documents and Settings\username\NetHood.

    CSIDL_NETWORK (0x0012)
        A virtual folder representing Network Neighborhood, the root of the network namespace hierarchy.

    CSIDL_PERSONAL (0x0005)
        Version 6.0. The virtual folder representing the My Documents desktop item. This is equivalent to CSIDL_MYDOCUMENTS.

        Previous to Version 6.0. The file system directory used to physically store a user'
s common repository of documents. A typical path is C:\Documents and Settings\username\My Documents. This should be distinguished from the virtual My Documents folder in the namespace. To access that virtual folder, use SHGetFolderLocation, which returns the ITEMIDLIST for the virtual location, or refer to the technique described in Managing the File System.

    CSIDL_PHOTOALBUMS (0x0045)
        Note  This documentation is preliminary and is subject to change.
        Windows Vista and later. The virtual folder used to store photo albums, typically username\My Pictures\Photo Albums.

    CSIDL_PLAYLISTS (0x003f)
        Note  This documentation is preliminary and is subject to change.
        Windows Vista and later. The virtual folder used to store play albums, typically username\My Music\Playlists.

    CSIDL_PRINTERS (0x0004)
        The virtual folder containing installed printers.

    CSIDL_PRINTHOOD (0x001b)
        The file system directory that contains the link objects that can exist in the Printers virtual folder. A typical path is C:\Documents and Settings\username\PrintHood.

    CSIDL_PROFILE (0x0028)
        Version 5.0. The user's profile folder. A typical path is C:\Documents and Settings\username. Applications should not create files or folders at this level; they should put their data under the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA.

    CSIDL_PROGRAM_FILES (0x0026)
        Version 5.0. The Program Files folder. A typical path is C:\Program Files.

    CSIDL_PROGRAM_FILES_COMMON (0x002b)
        Version 5.0. A folder for components that are shared across applications. A typical path is C:\Program Files\Common. Valid only for Windows NT, Windows 2000, and Windows XP systems. Not valid for Windows Millennium Edition (Windows Me).

    CSIDL_PROGRAMS (0x0002)
        The file system directory that contains the user'
s program groups (which are themselves file system directories). A typical path is C:\Documents and Settings\username\Start Menu\Programs. 

    CSIDL_RECENT (0x0008)
        The file system directory that contains shortcuts to the user's most recently used documents. A typical path is C:\Documents and Settings\username\My Recent Documents. To create a shortcut in this folder, use SHAddToRecentDocs. In addition to creating the shortcut, this function updates the Shell's list of recent documents and adds the shortcut to the My Recent Documents submenu of the Start menu.

    CSIDL_RESOURCES (0x0038)

    CSIDL_SAMPLE_MUSIC (0x0040)
        Note  This documentation is preliminary and is subject to change.
        Windows Vista and later. The file system directory that contains sample music. A typical path is C:\Documents and Settings\username\My Documents\My Music\Sample Music.

    CSIDL_SAMPLE_PLAYLISTS (0x0041)
        Note  This documentation is preliminary and is subject to change.
        Windows Vista and later. The file system directory that contains sample playlists. A typical path is C:\Documents and Settings\username\My Documents\My Music\Sample Playlists.

    CSIDL_SAMPLE_PICTURES (0x0042)
        Note  This documentation is preliminary and is subject to change.
        Windows Vista and later. The file system directory that contains sample pictures. A typical path is C:\Documents and Settings\username\My Documents\My Pictures\Sample Pictures.

    CSIDL_SAMPLE_VIDEOS (0x0043)
        Note  This documentation is preliminary and is subject to change.
        Windows Vista and later. The file system directory that contains sample videos. A typical path is C:\Documents and Settings\username\My Documents\My Videos\Sample Videos.

    CSIDL_SENDTO (0x0009)
        The file system directory that contains Send To menu items. A typical path is C:\Documents and Settings\username\SendTo.

    CSIDL_STARTMENU (0x000b)
        The file system directory containing Start menu items. A typical path is C:\Documents and Settings\username\Start Menu.

    CSIDL_STARTUP (0x0007)
        The file system directory that corresponds to the user's Startup program group. The system starts these programs whenever any user logs onto Windows NT or starts Windows 95. A typical path is C:\Documents and Settings\username\Start Menu\Programs\Startup.

    CSIDL_SYSTEM (0x0025)
        Version 5.0. The Windows System folder. A typical path is C:\Windows\System32.

    CSIDL_TEMPLATES (0x0015)
        The file system directory that serves as a common repository for document templates. A typical path is C:\Documents and Settings\username\Templates.

    CSIDL_WINDOWS (0x0024)
        Version 5.0. The Windows directory or SYSROOT. This corresponds to the %windir% or %SYSTEMROOT% environment variables. A typical path is C:\Windows.

Remarks

    These values supersede the use of environment variables for this purpose.

    A CSIDL is used in conjunction with one of four Shell functions, SHGetFolderLocation, SHGetFolderPath, SHGetSpecialFolderLocation, and SHGetSpecialFolderPath, to retrieve a special folder'
s path or pointer to an item identifier list (PIDL).

    Combine CSIDL_FLAG_CREATE with any of the other CSIDLs to force the creation of the associated folder. The remaining CSIDLs correspond to either file system folders or virtual folders. Where the CSIDL identifies a file system folder, a commonly used path is given as an example. Other paths may be used. Some CSIDLs can be mapped to an equivalent %VariableName% environment variable. CSIDLs are more reliable, however, and should be used if possible.


function GetShellFolder(CSIDL: integer): string;


function GetShellFolder(CSIDL: integer): string;
var
  pidl                   : PItemIdList;
  FolderPath             : string;
  SystemFolder           : Integer;
  Malloc                 : IMalloc;
begin
  Malloc := nil;
  FolderPath := '';
  SHGetMalloc(Malloc);
  if Malloc = nil then
  begin
    Result := FolderPath;
    Exit;
  end;
  try
    SystemFolder := CSIDL;
    if SUCCEEDED(SHGetSpecialFolderLocation(0, SystemFolder, pidl)) then
    begin
      SetLength(FolderPath, max_path);
      if SHGetPathFromIDList(pidl, PChar(FolderPath)) then
      begin
        SetLength(FolderPath, length(PChar(FolderPath)));
      end;
    end;
    Result := FolderPath;
  finally
    Malloc.Free(pidl);
  end;
end;

In die uses Klausel müssen noch die Units shlobj und ActiveX aufgenommen werden.

Diese Funktion eignet sich auch dazu andere spezielle Systemordner zu ermitteln. Übergibt man hier die Konstante CSIDL_APPDATA ($001A), bekommt man genau den gewünschten Ordner, nämlich C:\Dokumente und Einstellungen\<Benutzername>\Anwendungsdaten.