© J.C. Kessels 2009
MyDefrag Forum
May 25, 2013, 03:45:36 am
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
:
Home
Help
Search
Login
Register
MyDefrag Forum
>
JkDefrag v3 Forum
>
Programming with the library
>
Error Use Library In Delphi.
Pages:
1
2
[
3
]
4
« previous
next »
Print
Author
Topic: Error Use Library In Delphi. (Read 41012 times)
sonykalkan
JkDefrag Senior
Posts: 21
Error Use Library In Delphi.
«
Reply #30 on:
June 18, 2007, 02:46:41 pm »
You are totally right. Thank you for all of your suggestions and helps. I have forgotten to use new dll for my code, i replaced it and modified the codes you have mentioned accordingly.
It seems now that the code works without problem at least for analyse only mode. (I have only checked this mode yet.).
The code works in Lazarus Free Pascal IDE which is similar to Delphi. But i checked the code with Delphi, it gives exceptions. May be there is a problem with Delphi.
Now, i have questions about drawing colors. My code does not behave similar to your jkdefrag.exe executable. The shape of colors looks very different in mine. Is there a problem in my code ?
What i do for coloring is draw lines in TDefragDrawClusterCallback
The lines are drawn from point representing ClusterStart to point representing ClusterEnd. It is colored in the refering parameter color.
In my example, one line can only be 640 pixel wide so i continue the same colored cluster below the line.
Do i need another coloring in different callbacks (i.e showmove) ?
Thank you very much.
Regards,
Code:
procedure TDefragDrawClusterCallback(Data: PDefragDataStruct; ClusterStart, ClusterEnd: ULONG64; Color: Integer); CDECL;
var
rect:TRect;
newcolor:TColor;
i,j:integer;
totcluster:integer;
x1,y1,x2,y2:integer;
begin
totcluster:=data^.TotalClusters;
{
#define COLOREMPTY 0 /* Empty diskspace. */
#define COLORALLOCATED 1 /* Used diskspace / system files. */
#define COLORUNFRAGMENTED 2 /* Unfragmented files. */
#define COLORUNMOVABLE 3 /* Unmovable files. */
#define COLORFRAGMENTED 4 /* Fragmented files. */
#define COLORBUSY 5 /* Busy color. */
#define COLORMFT 6 /* MFT reserved zones. */
}
if(color=0 )then newcolor:=clBlack;
if(color=1 )then newcolor:=clPurple;
if(color=2)then newcolor:=$00FF00;
if(color=3)then newcolor:=clRed;
if(color=4)then newcolor:=clYellow;
if(color=5)then newcolor:=clWhite;
if(color=6)then newcolor:=$008000;
form1.Image1.Canvas.Pen.Color:=newcolor;
x1:=clusterstart mod 640;
x2:=clusterend mod 640;
y1:=clusterstart div 640;
y2:=clusterend div 640;
form1.image1.Canvas.MoveTo(x1,y1);
if(y2=y1) then
form1.image1.Canvas.LineTo(x2,y2);
if(y2>y1) then
begin
form1.image1.Canvas.LineTo(640,y1);
for i:=y1+1 to y2-1 do
begin
form1.image1.Canvas.MoveTo(0,i);
form1.image1.Canvas.LineTo(640,i);
end;
form1.image1.Canvas.MoveTo(0,y2);
form1.image1.Canvas.LineTo(x2,y2);
end;
form1.label2.caption:=inttostr(clusterstart)+':'+inttostr(clusterend)+':'+inttostr(data^.TotalClusters);
count1:=count1+1;
if(count1 mod 10000 = 0) then
Application.ProcessMessages;
end;
Logged
jeroen
Administrator
JkDefrag Hero
Posts: 7155
Error Use Library In Delphi.
«
Reply #31 on:
June 18, 2007, 05:31:26 pm »
Quote from: "sonykalkan"
You are totally right. Thank you for all of your suggestions and helps.
I am glad to hear that version 3.15 has solved the callback problems for you. I hope that you (and other Pascal programmers) can now turn out lot's of interesting applications containing the JkDefrag library. I like Pascal, it was one of the first programming languages that I learned.
Quote from: "sonykalkan"
Do i need another coloring in different callbacks (i.e showmove) ?
All drawing on the disk bitmap is done via the DrawCluster callback. The ClearScreen callback is the only other callback that performs actions on the disk bitmap.
Quote from: "sonykalkan"
Code:
x1:=clusterstart mod 640;
x2:=clusterend mod 640;
y1:=clusterstart div 640;
y2:=clusterend div 640;
I think this code does not do what you intend it to do. If the size of the harddisk is exactly 255999 clusters then the last cluster will be displayed on y=399 and x=639. But what if the disk is smaller, or bigger? In the begin of the code you grab "totcluster", but never use it after that.
Logged
sonykalkan
JkDefrag Senior
Posts: 21
Error Use Library In Delphi.
«
Reply #32 on:
June 21, 2007, 11:21:19 am »
Hi again,
I think i found a clue about the problem in delphi. I made a debug on delphi dll and see that nil parameter for pointers behaves as 0 but not null
Can you reorganize the new release of your dll so that it check null as well as 0 for pointers.
As a reference:
Pointer types
A Pointer type is stored in 4 bytes as a 32-bit address. The pointer value nil is stored as zero.
taken from:
http://info.borland.com/techpubs/delphi/delphi5/oplg/memory.html
Best regards,
Logged
jeroen
Administrator
JkDefrag Hero
Posts: 7155
Error Use Library In Delphi.
«
Reply #33 on:
June 21, 2007, 12:23:44 pm »
Quote from: "sonykalkan"
Can you reorganize the new release of your dll so that it check null as well as 0 for pointers.
It already does that, because NULL and 0 pointers are exactly the same.
The Excludes, SpaceHogs, and DebugMsg parameters must be a pointer to an array of pointers. Please note that the last entry in these arrays must be "nil" (see the SpaceHogs in the example Pascal program), so the library knows where the array ends. Also note that in Pascal a pointer to an empty array is not the same as a nil pointer.
Logged
sonykalkan
JkDefrag Senior
Posts: 21
Error Use Library In Delphi.
«
Reply #34 on:
June 26, 2007, 04:30:41 pm »
Hi again,
Below are what i noticed since my previous message:
I have managed to communicate delphi and your c++ dll. It is a little bit complicated, In summary, i wrote a passer dll in free pascal. It receives calls from dll written in Delphi and run the appropriate dll function written in c++
just like:
Code:
Procedure RunDefrag(
Path: PWideChar;
Mode: Integer;
Speed: Integer;
FreeSpace: Double;
Excludes: array of PWideChar;
SpaceHogs: array of PWideChar;
Running: PInteger;
RedrawScreen: PInteger;
ShowStatus, ShowMove, ShowAnalyze, ShowDebug, DrawCluster, ClearScreen: Pointer;
DebugMsg: array of PWideChar);
stdcall;
var parstr:string;
spacehogs1:array of pwidechar=nil;
Excludes1:array of pwidechar=nil;
DebugMessages1:array of pwidechar=nil;
begin
RunJkDefrag(
Path,
Mode,
Speed,
FreeSpace,
Excludes1,
SpaceHogs1,
Running,
RedrawScreen,
ShowStatus, ShowMove, ShowAnalyze, ShowDebug, DrawCluster, nil,
DebugMessages1);
end;
end;
In other words, Rundefrag procedure is a dll procedure of free pascal. Delphi runs Rundefrag using stdcall but not CDECL
then, free pascal runs RunJkdefrag in CDECL because your c++ dll uses this method.
In this way the software i wrote in Delphi runs nearly without problem.
But there are some problems also:
* I must use nil for @TDefragShowDebugCallback maybe because
Args: Array of const parameter does not fit ... in c++
An exception occurs when i do not use nil
Code:
procedure TDefragShowDebugCallback(Level: Integer; Item: PItemStruct; Msg: PChar; Args: Array of const); CDECL;
* When i assign mode as 6 (6 = Analyze and move to end of disk.). My software does not behave as expected. Mine starts from phase 4 but your exe starts from phase 3(move up)
I did not check other modes but i checked default mode 3. It starts from phase 2 (fixup) for both your software and mine.
So there can be an inconsistency in modes for dll except mode 3.
* I want to learn percentage of defrag process. How do i get it ?
Regards,
Logged
jeroen
Administrator
JkDefrag Hero
Posts: 7155
Error Use Library In Delphi.
«
Reply #35 on:
June 26, 2007, 10:29:43 pm »
Quote from: "sonykalkan"
Delphi runs Rundefrag using stdcall but not CDECL
Well, I'm sure you're right, but stdcall did not work for me when I tried the DLL with FreePascal. Before version 3.15 I used stdcall, but I switched to cdecl in version 3.15. So I don't know, it's one or the other.
Quote from: "sonykalkan"
* I must use nil for @TDefragShowDebugCallback maybe because
Args: Array of const parameter does not fit ... in c++
That's what happened to me when I used stdcall. It works in free pascal with cdecl.
Quote from: "sonykalkan"
So there can be an inconsistency in modes for dll except mode 3.
For the library you have to subtract 1 from the commandline parameter. Mode 3 in the library is mode 4 on the commandline, which does not exist any more and is executed as mode 3.
Quote from: "sonykalkan"
* I want to learn percentage of defrag process. How do i get it ?
That's actually quite complicated. I cannot explain. See the "progress" variables in the Data struct, and look for "progress" in the "jkdefragwindows.cpp" source.
Logged
sonykalkan
JkDefrag Senior
Posts: 21
Error Use Library In Delphi.
«
Reply #36 on:
June 27, 2007, 02:15:47 pm »
I forgot to say:
My software hangs when entering ShowMoveCallback routine with huge clustersize
i.e when moving 20000 clusters.
After moving of clusters ends, the software gives response again.
I want to put a Application.ProcessMessages wherever it must be, so that i can repaint my form while moving continues, but i cannot find the right callback.
I assume that the right callback to put processmessages may be ShowDebugCall but you know, i choose it nil because of the reasons that i described.
Logged
jeroen
Administrator
JkDefrag Hero
Posts: 7155
Error Use Library In Delphi.
«
Reply #37 on:
June 27, 2007, 07:00:34 pm »
Quote from: "sonykalkan"
After moving of clusters ends, the software gives response again.
That is normal. JkDefrag is based on the Microsoft defragmentation API. Basically all it does is instruct the API to move a file to a particular location on disk. Huge files will take a long time. It is not JkDefrag that is moving the file. The callbacks are only invoked before and after a file moves, not while a file is being moved.
Logged
sonykalkan
JkDefrag Senior
Posts: 21
Error Use Library In Delphi.
«
Reply #38 on:
June 28, 2007, 06:50:53 am »
But i see that your jkdefrag.exe shows percentage and give response to outer events while a single moving event of huge cluster sizes continues. But in my software the same moving hangs till the moving ends. That was my question.
Regards,
Logged
sonykalkan
JkDefrag Senior
Posts: 21
Error Use Library In Delphi.
«
Reply #39 on:
June 28, 2007, 01:52:37 pm »
I have checked your jkdefrag.cpp code and cannot find how did you do Application.DoEvents(); or similar to enable closing the software while moving clusters. I see that percentage values increases when a single moving event occurs and i can drag your executable form from the title bar smootly. But my software did not give any response to any event when moving large number of clusters occurs.
Logged
jeroen
Administrator
JkDefrag Hero
Posts: 7155
Error Use Library In Delphi.
«
Reply #40 on:
June 28, 2007, 06:42:45 pm »
Like I said, it's quite complicated. JkDefrag does not show the percentage directly via a callback, but via a timer that updates the screen 3 times per second. See the "PaintScreen" subroutine in the JkDefragWindows.cpp" source. The timer estimates the percentage based on the last "progress" values it got from the last DrawCluster callback. It's basically a ticking clock. It does not know how far the filemove has really progressed.
Logged
sonykalkan
JkDefrag Senior
Posts: 21
Error Use Library In Delphi.
«
Reply #41 on:
June 29, 2007, 08:51:49 am »
Sorry for insisting this question but I want to use a timer in my software with lets say 1sec intervals. But when I call RunJkDefrag and it is in moving state, my timer event cannot be accessed in the specified interval.
The software waits moving process finishes (even more than 1 minute) and then access timer event. Can you implement a timer event in your future releases ? It will be more convenient for all dll users who do not want their software hanging a long time
Thank you in advance,
Best regards,
Logged
jeroen
Administrator
JkDefrag Hero
Posts: 7155
Error Use Library In Delphi.
«
Reply #42 on:
June 29, 2007, 08:21:45 pm »
Quote from: "sonykalkan"
Can you implement a timer event in your future releases ?
JkDefrag CANNOT call the callbacks during a move, because the Microsoft API does not return until the file has been moved. I suggest that you run JkDefrag in a separate thread inside your program.
Logged
puma
Newbie
Posts: 4
Re: Error Use Library In Delphi.
«
Reply #43 on:
June 10, 2008, 11:24:01 am »
Dear sonekalkan & jaroen:
Im new at delphi and want to include the library files....... please tell me the procdeure as Im getting the following error
Exception EAccessViolation in module JkDefragLib.dll at 00008C27.
Access violation at address 10008C27 in module 'JkDefragLib.dll'. Write of addr
ss 00000002.
Logged
jeroen
Administrator
JkDefrag Hero
Posts: 7155
Re: Error Use Library In Delphi.
«
Reply #44 on:
June 11, 2008, 05:56:01 am »
Quote from: puma on June 10, 2008, 11:24:01 am
Im getting the following error
I'm sorry but you will have to give a bit more information than that. Do you get this error message while compiling the example?
Logged
Pages:
1
2
[
3
]
4
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
MyDefrag v4 Forum
-----------------------------
=> Announcements
=> Questions and help
=> Bugs and problems
=> Requests for new features
=> Scripts, and other contributions
-----------------------------
JkDefrag v3 Forum
-----------------------------
=> Announcements
=> Questions and help
=> Bugs and problems
=> Requests for new features
=> Programming with the library
Loading...