msmouse
asked on
Problem changing from Strings to Array
I am getting data from an Access database. Two Fields 'Servers' and 'Drives'. I then want to Select the first Server and the FIRST drive Letter ( then I will go back and get the second drive Letter) I want to take the Server Name and Drive letter to make a Network Connection. The trouble I am having is when I try to add the strings to the array? I then get the incompatable types sting and Pchar. Any input on how to get the database information into the WNetAddConection?
Here is how I get the Information from the database
procedure TForm1.Button1Click(Sender : TObject);
var
DriverArray : Array[0..8] of char;
begin
if Table1.FieldByName ('drives').AsString<> '' then
begin
S := Table1.FieldByName ('ServerName').AsString+ ' ';
D := Table1.FieldByName ('drives').AsString;
DBServerList.Items.Add(S);
{Move(D[1], DriverArray,Length(D));
Memo1.Lines.Append(DriverA rray[1]);}
end;
//LOOP THRU the DRIVES
procedure TForm1.Button2Click(Sender : TObject);
var
MyArray : array[0..10] of char;
y : integer;
begin
Move(D[1], MyArray, Length(D));
y:= 0;
WHile (MyArray[y] <> #0) do
begin
ListBox1.Items.Add(MyArray [y]);
Memo1.Lines.Add(MyArray[y] );
y:= y+1;
end;
end;
procedure TForm1.Button3Click(Sender : TObject);
begin
Table1.Next;
Memo1.Lines.Clear;
end;
HERE IS WHERE THE PROBLEMS START!!!!
procedure TForm1.Button4Click(Sender : TObject);
var
NR : TNetResource;
NetArray : String;
//NetArray : array [0..15] of char;
x : integer;
begin
// NetArray := '\\CEC-A\C$';
NetArray := '\\' + S + '\' + D + '$';// NEEDS TO BE ENTERED LIKE THIS
FillChar(NR, SizeOf(NR),0);
NR.dwType := RESOURCETYPE_DISK;
NR.lpLocalName := 'E:';
NR.lpRemoteName := NetArray;
WNetAddConnection2 (NR, nil, nil, 0);
end;
IF I assign the entire Servername and drive to the array the connections occur. I am trying to get this so the connections and disconnects occur automaticly. While the connections are made I get the Drive SIze and Free Space.
Here is how I get the Information from the database
procedure TForm1.Button1Click(Sender
var
DriverArray : Array[0..8] of char;
begin
if Table1.FieldByName ('drives').AsString<> '' then
begin
S := Table1.FieldByName ('ServerName').AsString+ ' ';
D := Table1.FieldByName ('drives').AsString;
DBServerList.Items.Add(S);
{Move(D[1], DriverArray,Length(D));
Memo1.Lines.Append(DriverA
end;
//LOOP THRU the DRIVES
procedure TForm1.Button2Click(Sender
var
MyArray : array[0..10] of char;
y : integer;
begin
Move(D[1], MyArray, Length(D));
y:= 0;
WHile (MyArray[y] <> #0) do
begin
ListBox1.Items.Add(MyArray
Memo1.Lines.Add(MyArray[y]
y:= y+1;
end;
end;
procedure TForm1.Button3Click(Sender
begin
Table1.Next;
Memo1.Lines.Clear;
end;
HERE IS WHERE THE PROBLEMS START!!!!
procedure TForm1.Button4Click(Sender
var
NR : TNetResource;
NetArray : String;
//NetArray : array [0..15] of char;
x : integer;
begin
// NetArray := '\\CEC-A\C$';
NetArray := '\\' + S + '\' + D + '$';// NEEDS TO BE ENTERED LIKE THIS
FillChar(NR, SizeOf(NR),0);
NR.dwType := RESOURCETYPE_DISK;
NR.lpLocalName := 'E:';
NR.lpRemoteName := NetArray;
WNetAddConnection2 (NR, nil, nil, 0);
end;
IF I assign the entire Servername and drive to the array the connections occur. I am trying to get this so the connections and disconnects occur automaticly. While the connections are made I get the Drive SIze and Free Space.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or, you can use:
StrPCopy( NetArray, '\\' + S + '\' + D + '$' ) ;
To do the same thing without casting...
Tim.
StrPCopy( NetArray, '\\' + S + '\' + D + '$' ) ;
To do the same thing without casting...
Tim.
listenning
msmouse, have you had success?
ASKER
StrPCopy also works, I'll have to decide which way will work the best. Thanks
ASKER
Thanks